0

I have this tsconfig.json file

{
  "compilerOptions": {
    "target": "es2019",
    "lib": [
      "es2020",
      "esnext.asynciterable"
    ],
    "typeRoots": [
      "./node_modules/@types",
      "./src/types"
    ],
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node",
    "module": "commonjs",
    "pretty": true,
    "sourceMap": true,
    "outDir": "./build",
    "allowJs": true,
    "noEmit": false
  },
  "include": [
    "./src/**/*"
  ],
  "exclude": [
    "node_modules",
    "tests"
  ]
}

As far as you can see there are no strict rules there. The most important for me it's starting to use strictNullChecks setting, but my project is already large, and when I set this setting to true I've got ~1000 errors.

I want to start refactor code for avoiding potential issues, but I want to move step by step, file by file and don't want to spend time resolving 1000 errors at once.

How can I achieve it? I had a plan to use a comment // @ts-ignore for each error line and then incrementally resolve problems. But it's even hard to add // @ts-ignore 1000 times. How can I do it automatically? Any advice please

Oro
  • 2,250
  • 1
  • 6
  • 22

1 Answers1

2

I think one approach was using multiple tsconfig.json files. Start adding them at the "leaves" and move them further up the hierarchy as the stricter types get added. These files can be based on a root config using "extends". Using multiple configs apparently can be tricky, though.

If this does not work you can add just one config and manually list files that have been migrated; the VS Code team did this.

{
    "extends": "./tsconfig.base.json", // Shared configuration with our main `tsconfig.json`
    "compilerOptions": {
        "noEmit": true, // Don't output any javascript
        "strictNullChecks": true
    },
    "files": [
        // Slowly growing list of strict null check files goes here
    ]
}
H.B.
  • 166,899
  • 29
  • 327
  • 400