β‡’ Basic Types

Basic Types

β‡’ Config for Simple Node.js Project - tslint.json


β‡’ Tipagens para Libs sem tipagem

Create custom type definitions for JavaScript dependencies


β‡’ Tsconfig Paths

Adding @ in imports - Short paths

tsconfig.paths.json β†’ Example

{
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "@assets": ["./assets/index"],
      "@assets/*": ["./assets/*"],
      "@contexts": ["./contexts/index"],
      "@contexts/*": ["./contexts/*"],
      "@components": ["./components/index"],
      "@components/*": ["./components/*"],
      "@hooks": ["./hooks/index"],
      "@hooks/*": ["./hooks/*"],
      "@libs/*": ["./libs/*"],
      "@modules/*": ["./modules/*"],
      "@services/api": ["./services/api/index"],
      "@services/api/*": ["./services/api/*"],
      "@services/*": ["./services/*"],
      "@shared/*": ["./shared/*"],
      "@store": ["./store/index"],
      "@store/*": ["./store/*"],
      "@styles": ["./styles/index"],
      "@styles/*": ["./styles/*"],
      "@utils": ["./utils/index"],
      "@utils/*": ["./utils/*"]
    }
  }
}

Need to add in the tsconfig.json

"extends": "./tsconfig.paths.json"

Utilizando Path Mapping no TypeScript


β‡’ Generic Type in Arrow Functions (Type Template)

**const foo = <T,>(x: T) => x;**
// or
const foo = <T extends unknown>(x: T) => x;