Skip to content

Instantly share code, notes, and snippets.

@dpeek
Created August 30, 2023 01:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpeek/536a2069a192640d8b1698c350150223 to your computer and use it in GitHub Desktop.
Save dpeek/536a2069a192640d8b1698c350150223 to your computer and use it in GitHub Desktop.
Somewhat OK TSConfig defaults and explanations
/*
Enabled by "strict":
- alwaysStrict
- noImplicitAny
- noImplicitThis
- strictNullChecks
- strictBindCallApply
- strictFunctionTypes
- strictPropertyInitialization
- useUnknownInCatchVariable
Not needed because we're not emitting:
- sourceRoot
- noEmitOnError
- outFile
- preserveConstEnums
- removeComments
- verbatimModuleSyntax
- sourceMap
- inlineSourceMap
- inlineSources
- jsxFactory
- jsxFragmentFactory
- jsxImportSource
- downlevelIteration
- importHelpers
- noEmitHelpers
- useDefineForClassFields
Defaults are fine:
- allowUnreachableCode: warns by default
- allowUnusedLabels: warns by default
- noFallthroughCasesInSwitch: useful
- noUnusedParameters: _ prefix to ignore feels hacky
- newLine: let tsc decide
Misc:
- incremental: enabled by "composite"
- noEmit: using "emitDeclarationOnly" instead
- allowSyntheticDefaultImports: enabled by "esModuleInterop"
- baseUrl: not recommended
- declarationDir: set by "outDir" if "declaration" is true
*/
{
"compilerOptions": {
// input / output
"rootDir": "./src" /* all source files in src */,
"outDir": "./out" /* emit declarations and tsbuildinfo here */,
"declaration": true /* emit declarations */,
"declarationMap": true /** generate declaration source maps */,
"emitDeclarationOnly": true /* emit declarations only */,
// type checking
"strict": true /* highly recommended */,
"exactOptionalPropertyTypes": true /* optional properties can be defined or not defined, but not undefined */,
"noImplicitOverride": true /* check accidental super class function rename */,
"noImplicitReturns": true /* check accidental undefined function return */,
"noPropertyAccessFromIndexSignature": true /* don't allow index to be accessed as property, important for next setting */,
"noUncheckedIndexedAccess": true /* check index access for undefined */,
"noUnusedLocals": true /* check unused local variables */,
"skipLibCheck": true /* don't check lib files */,
// target runtime
"target": "esnext" /* modern output */,
"lib": ["esnext", "dom"] /* change based on target runtime */,
// module resolution
"module": "esnext" /* modern modules */,
"moduleResolution": "bundler" /* bundler will handle resolution */,
"forceConsistentCasingInFileNames": true /* check file name casing matches import */,
"allowArbitraryExtensions": true /* allow importing other resources */,
"allowImportingTsExtensions": true /* otherwise you have to add .js to your imports */,
"moduleDetection": "force" /* ensure all non-declaration files are modules */,
"isolatedModules": true /* warn about things that per-file bundlers can't handle */,
"resolveJsonModule": true /* allow json imports */,
"esModuleInterop": true /* allow default imports from commonjs modules */,
"composite": true /* allow project references */,
"allowJs": true /* allow importing js from ts */,
"checkJs": true /* type check js imports */,
"jsx": "react-jsx" /** allow jsx */
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment