TypeScript: Difference between revisions

No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 3: Line 3:


==Syntax==
==Syntax==
Here we focus on the syntax differences between TypeScript and JavaScript.
Here we focus on the syntax differences between TypeScript and JavaScript. See [[JavaScript]] for JS syntax.


===Classes===
===Classes===
Line 26: Line 26:


TypeScript does not support overloading in the traditional sense, with multiple implementations.   
TypeScript does not support overloading in the traditional sense, with multiple implementations.   
However you can have multiple function definitions similar to prototypes.
However you can have multiple function declarations similar to prototypes.


===Interfaces===
===Interfaces===
[https://www.typescriptlang.org/docs/handbook/interfaces.html Interfaces]
[https://www.typescriptlang.org/docs/handbook/interfaces.html Interfaces]


Unlike JavaScript, TypeScript comes with support for interfaces:
Unlike JavaScript, TypeScript comes with support for interfaces.<br>
You can treat these interfaces as types or structs.
<syntaxhighlight lang="typescript">
<syntaxhighlight lang="typescript">
interface LabeledValue {
interface LabeledValue {
Line 43: Line 44:
===Type Guards===
===Type Guards===
[https://www.typescriptlang.org/docs/handbook/advanced-types.html Advanced Types]
[https://www.typescriptlang.org/docs/handbook/advanced-types.html Advanced Types]


==Compilation==
==Compilation==
Line 56: Line 55:
#:<pre>npm install -g typescript</pre>
#:<pre>npm install -g typescript</pre>
# Compile your typescript file
# Compile your typescript file
#:<pre>tsc greeter.js</pre>
#:<pre>tsc greeter.ts</pre>


===webpack===
===webpack===
Line 66: Line 65:
==Resources==
==Resources==
* [https://www.typescriptlang.org/docs/handbook/intro.html The TypeScript Handbook]
* [https://www.typescriptlang.org/docs/handbook/intro.html The TypeScript Handbook]
[[Category:Programming languages]]