What is TypeScript and why would I use it in place of JavaScript

Mots clés : javascripttypescriptjavascript

meilleur 2 Réponses What is TypeScript and why would I use it in place of JavaScript

vote vote

100

class Greeter {     greeting: string;     constructor (message: string) {         this.greeting = message;     }     greet() {         return "Hello, " + this.greeting;     } }   
var Greeter = (function () {     function Greeter(message) {         this.greeting = message;     }     Greeter.prototype.greet = function () {         return "Hello, " + this.greeting;     };     return Greeter; })(); 
vote vote

81

let x: number | undefined; if (x !== undefined) x += 1; // this line will compile, because x is checked. x += 1; // this line will fail compilation, because x might be undefined. 

Questions similaires