Skip to content

Instantly share code, notes, and snippets.

@aqzhyi
Last active December 7, 2024 16:09
Show Gist options
  • Save aqzhyi/99b889aff9c025d9b804fa8cd2a7db1b to your computer and use it in GitHub Desktop.
Save aqzhyi/99b889aff9c025d9b804fa8cd2a7db1b to your computer and use it in GitHub Desktop.
tsconfig.json for typescript^5
/** also see https://www.totaltypescript.com/tsconfig-cheat-sheet */
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"allowUmdGlobalAccess": true,
"allowUnreachableCode": true,
"allowUnusedLabels": false,
"alwaysStrict": true,
"baseUrl": ".",
"composite": true, // useful monorepo. tell TypeScript to create a .tsbuildinfo file. this tells TypeScript that your project is part of a monorepo and helps cache builds to make them faster
"declaration": true, // useful monorepo
"declarationMap": true, // useful monorepo
"esModuleInterop": true,
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
"incremental": true,
"inlineSources": true,
"isolatedModules": true,
"lib": ["dom", "dom.iterable", "esnext", "WebWorker"],
"module": "ESNext",
"moduleDetection": "force", // why "force"? this option forces TypeScript to treat all files as modules. this helps to avoid the error "cannot redeclare block-scoped variable"
"moduleResolution": "Bundler", // why "Bundler"? if you bundle with tools like Webpack, Rollup, Babel, SWC, or ESBuild, then "Bundler" is the best choice
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": false, // why false? let's see what props can be used in the callback
"pretty": true,
"resolveJsonModule": true,
"removeComments": false, // why false? if you are developing a package, I believe it is unreasonable to remove comments (JSDoc)
"skipLibCheck": true,
"sourceMap": true, // useful monorepo
"strict": true,
"strictBindCallApply": true,
"strictNullChecks": true,
"target": "ESNext",
"tsBuildInfoFile": "./dist/tsconfig.tsbuildinfo",
"useDefineForClassFields": true, // when target is ESNext or ES2020 and above, set it to true to match the standard ECMAScript runtime behavior
"useUnknownInCatchVariables": true,
"verbatimModuleSyntax": true,
"outDir": "./dist"
},
"include": ["src", "vite.config.ts"],
"exclude": ["node_modules"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment