Outils pour utilisateurs

Outils du site


web:javascript:typescript

Ceci est une ancienne révision du document !


TypeScript

Installation

  1. Installer node.js
  2. Installer TypeScript par npm : # npm install -g typescript

Linting

  • Visual Studio Code a une extension : TSLint
  • Linter Documentation : TSLint

Pour installer:

$ npm i -g tslint

Compilation / Transpile

En installant TypeScript, on installe un transpiler qui transforme le code TypeScript en JavaScript.

$ tsc fichier.ts

Typings

Interface

class ICat {
    name: string;
    age: number;
}
 
let fluffy: ICat;

Classes

class Cat implements ICat {
    private name: string;
    private color: string;
 
    constructor (name, color) {
        this.name = name;
        this.color = color;
    }
 
    speak() {
        console.log('meow');
    }
}

Peut être remplacé par :

class Cat implements ICat {   
    constructor (private name, private color) {
 
    }
 
    speak() {
        console.log('meow');
    }
}

Ressources

web/javascript/typescript.1522280660.txt.gz · Dernière modification : 2022/02/02 00:43 (modification externe)