Skip to content

TS configuration

TS project folder structure

  • A src directory: place the code ("rootDir": "./src")
  • A build directory: to place the output of the build ("outDir": "./build")

TS configuration on VSCODE

  • Prettier extension
  • "prettier.singleQuote": true
  • "prettier.trailingComma": "none"
  • Editor
  • "editor.minimap.enabled": false
  • "editor.tabSize": 2

tsconfig.json

  • Compiler configuration file
  • Customize how the compiler behaves
  • tsc --init: Creates the config file
  • "rootDir": "./src": Defines the root folder
  • "outDir": "./build": Places the compiled code

Strict Type-Checking Options

  • By default the strict mode is FALSE
  • By generating the config (tsc --init) it changes to true ("strict": true )
interface HasId {
  id?: number;
}
// If an object implemented this interface, the id would be always a NUMBER!
// With strict mode it can be a number or undefined!

Export vs Export default

  • Convention in TS is to never use export default (although it's possible)