Strict tsconfig

JSON pattern

Adds "strict": true, "allowJs": true, "checkJs": false from a tsconfig's compilerOptions, and then removes existing redundant options (such as noImplicitAny).


Apply with the Grit CLI
grit apply strict_tsconfig

Transform standard tsconfig.json

BEFORE
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "types": ["node"],
    "foo": "bar"
  },
  "exclude": ["**/*.spec.ts"],
  "include": ["**/*.ts"]
}
AFTER
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "strict": true, "allowJs": true, "checkJs": false, "outDir": "../../dist/out-tsc",
    "types": ["node"],
    "foo": "bar"
  },
  "exclude": ["**/*.spec.ts"],
  "include": ["**/*.ts"]
}

Handles redundant options

BEFORE
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "types": ["node"],
    "foo": "bar",
    "baz": "raz"
  },
  "exclude": ["**/*.spec.ts"],
  "include": ["**/*.ts"]
}
AFTER
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "strict": true, "allowJs": true, "checkJs": false, "outDir": "../../dist/out-tsc",
    "types": ["node"],
    "foo": "bar",
    "baz": "raz"
  },
  "exclude": ["**/*.spec.ts"],
  "include": ["**/*.ts"]
}

Handles existing strict

BEFORE
{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "noImplicitAny": false,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "baseUrl": ".",
    "paths": {
      "@/*": ["./*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}
AFTER
{
  "compilerOptions": {
    "checkJs": false, "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "noImplicitAny": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "baseUrl": ".",
    "paths": {
      "@/*": ["./*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}

Bugfix $decl <: false

BEFORE
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "module": "commonjs",
    "types": ["node", "express"],
    "allowJs": true
  },
  "exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"],
  "include": ["**/*.ts"]
}
AFTER
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "strict": true, "checkJs": false, "outDir": "../../dist/out-tsc",
    "module": "commonjs",
    "types": ["node", "express"],
    "allowJs": true
  },
  "exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"],
  "include": ["**/*.ts"]
}