Skip to content

1.Tutorials

TS in 5 mins

  • Installation
    • npm install -g typescript
  • First file:
    • *.ts
    • Transpilation :
      • tsc <fichier>.ts [options]
      • Création d'un fichier <fichier>.js
      • Une erreur de transpilation n'empêche pas la génération du fichier JS !
    • Annotations:
      • Permet un typage un peu plus fort que JS, typage des arguments et propriétés…
      • Reporte une erreur à la transpilation
    • Interfaces:
      • Two types are compatible if their internal structure is compatible (= les mêmes propriétés sont présentes)
      • Permet de se passer de l'instruction "implements" dans d'autres langages POO
    • Classes:
      • Création de propriétés public à la volée possible via constructeur

TS in VSCode

  • https://code.visualstudio.com/docs/typescript/typescript-tutorial
  • Compilation:
    • Via terminal intégré + commande tsc <fichier>.ts [options]
    • Ajout d'un fichier tsconfig.json dans le répertoire pour y spécifier les options de transpilation
      • Transpile tous les fichier *.ts du répertoire courant et sous répertoires
      • Commande tsc sans fichiers ni options (s'appuie alors sur tsconfig.json)

TS compiling in VS Code

TS debugging in VS Code

  • https://code.visualstudio.com/docs/typescript/typescript-debugging
  • Config:
    • Default Node.js debugging config
    • Mapping JS <-> TS :
      • Soit option --sourcemap de transpilation (+ fichiers à transpiler)
        • tsc test.ts --sourcemap
      • Soit propriété sourceMap du fichier tsconfig.json à true (sans indiquer de fichier)
        • tsc
  • Launch.json
    • Construit à la volée par VSCode si tsc lancé avec sourcemap
    • Autrement le construire : Debugger > "Ouvrir launch.json" (roue crantée)