Typescript
What is it? Best practices, tips...
Thomas Winckell
Guillaume Monnet
@255kb
What is Typescript?
Any overhead?
No it’s only during development. After transpiling types disappear.
Usage / Configuration
Install TypeScript dependency npm install -D typescript
Compile .ts files with tsc command
tsc generates one .d.ts file (definition) and one .js file per ts file
Configure TypeScript compiler with tsconfig.json file
Can be generated using tsc --init
Where to install the compiler
IDE
Webstorm:
VSCode:
TSlint
Typescript linter.
Install with npm install -D tslint and run tslint --init get default tslint.json config file.
Will start by extending ”tslint:recommended” set of rules, you can add any rule in ”rules” array as long as rules are “imported” in the rulesDirectory array.
Popular rules libs: Codelyzer (Angular), SonarTS (Sonarqube)
Usage with Babel / Webpack
Basic types
Primitives, enums, arrays, any...
Environment
Library types
Classes
Modifiers, constructor...
Type composition
Operators, interface, type...
Type assertion (cast)
Type inference
Index signatures and mapped types
Generics
Built-in types
Partial, Pick...
Decorators
/!\ Experimental
Reflect metadata
/!\ Experimental
Links / sources
Try it: http://www.typescriptlang.org/play/
Presentation examples: https://github.com/255kb/typescript-js-meetup
Documentation: https://www.typescriptlang.org
Libraries types: https://github.com/DefinitelyTyped/DefinitelyTyped
TSLint rules:
https://palantir.github.io/tslint/rules/
https://github.com/mgechev/codelyzer https://github.com/SonarSource/SonarTS
Awesome list: https://github.com/dzharii/awesome-typescript