Cheat Sheet - TypeScript

Vocabular

What is a package?

What is a module?

Question & answers

When importing an ES module using the import statement, should I use a file extension, and if yes, which one?

package.json

exports

tsconfig.json

include

exclude

rootDir (modules)

baseUrl (modules)

paths (modules)

outDir (emit)

tsconfig used by Turbo Repo

{
  // Type checking
  "noUncheckedIndexedAccess": true,
  "strict": true,

  // Modules
  "module": "NodeNext" | "ESNext", 
  "moduleResolution": "Bundler",
  "resolveJsonModule": true,
  "rootDir": "src",
  
  // Emit
  "declaration": true,
  "declarationMap": true,
  "outDir": "dist",

  "noEmit": true

  // JavaScript support 
  "allowJs": true,

  // Editor support 
  "plugins" [{ "name": "next" }],

  // Interop constraints
  "esModuleInteropt": true, 
  "isolatedModules": true

  // Backwards compatibility

  // Language and environment 
  "lib": ["es2022", "DOM", "DOM.Iterable"],
  "moduleDetection": "force",
  "target": "ES2022",
  "jsx": "preserve",

  // Compiler diagnostics

  // Projects
  "incremental": false,

  // Output formatting 

  // Completeness
  "skipLibCheck": true,

  // Command line 

  // Watch options
}

tsconfig.json

The TSConfig Cheat Sheet
Learn the essential TypeScript configuration options and create a concise tsconfig.json file for your projects with this helpful cheatsheet.
GitHub - tsconfig/bases: Hosts TSConfigs to extend in a TypeScript app, tuned to a particular runtime environment
Hosts TSConfigs to extend in a TypeScript app, tuned to a particular runtime environment - tsconfig/bases
TSConfig Reference - Docs on every TSConfig option
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.

{
  "compilerOptions": {
    /* Base Options: */
    "esModuleInterop": true,
    "skipLibCheck": true,
    "target": "es2022",
    "allowJs": true,
    "resolveJsonModule": true,
    "moduleDetection": "force",
    "isolatedModules": true,
    "verbatimModuleSyntax": true,

    /* Strictness */
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitOverride": true,

    /* If transpiling with TypeScript: */
    "module": "NodeNext",
    "outDir": "dist",
    "sourceMap": true,

    /* AND if you're building for a library: */
    "declaration": true,

    /* AND if you're building for a library in a monorepo: */
    "composite": true,
    "declarationMap": true,

    /* If NOT transpiling with TypeScript: */
    "module": "preserve",
    "noEmit": true,

    /* If your code runs in the DOM: */
    "lib": ["es2022", "dom", "dom.iterable"],

    /* If your code doesn't run in the DOM: */
    "lib": ["es2022"]
  }
}