Skip to content

Instantly share code, notes, and snippets.

@dilame
Last active May 30, 2025 21:14
Show Gist options
  • Save dilame/32709f16e3f8d4d64b596f5b19d812e1 to your computer and use it in GitHub Desktop.
Save dilame/32709f16e3f8d4d64b596f5b19d812e1 to your computer and use it in GitHub Desktop.
The most strict TypeScript tsconfig mode
{
"compilerOptions": {
// Strict Checks
"alwaysStrict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"useUnknownInCatchVariables": true,
"strictPropertyInitialization": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"strictBindCallApply": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
// Linter Checks
"noImplicitReturns": true,
"noImplicitOverride": true,
"forceConsistentCasingInFileNames": true,
// https://eslint.org/docs/rules/consistent-return ?
"noFallthroughCasesInSwitch": true,
// https://eslint.org/docs/rules/no-fallthrough
"noUnusedLocals": true,
// https://eslint.org/docs/rules/no-unused-vars
"noUnusedParameters": true,
// https://eslint.org/docs/rules/no-unused-vars#args
"allowUnreachableCode": false,
// https://eslint.org/docs/rules/no-unreachable ?
"allowUnusedLabels": false,
// https://eslint.org/docs/rules/no-unused-labels
// Base Strict Checks
"noImplicitUseStrict": false,
"suppressExcessPropertyErrors": false,
"suppressImplicitAnyIndexErrors": false,
"noStrictGenericChecks": false
}
}
@alwalxed
Copy link

alwalxed commented Jul 28, 2024

Thanks a lot, next.js comes with default strict settings. Here are their default tsconfig.json settings:

{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"],
}

Since "strict": true includes most of the settings you mentioned, I only had to add these:

{
  "noPropertyAccessFromIndexSignature": true,
  "noUncheckedIndexedAccess": true,
  "exactOptionalPropertyTypes": true,
  "noImplicitReturns": true,
  "noImplicitOverride": true,
  "forceConsistentCasingInFileNames": true,
  "noFallthroughCasesInSwitch": true,
  "noUnusedLocals": true,
  "noUnusedParameters": true,
  "allowUnreachableCode": false,
  "allowUnusedLabels": false
}

@mohd-akram
Copy link

forceConsistentCasingInFileNames is true by default since 5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment