Skip to content

feat(create-vite): set "strict: true" in tsconfig.node.json#15820

Merged
patak-cat merged 1 commit intovitejs:mainfrom
philbates35:tsconfig-node-strict
Feb 8, 2024
Merged

feat(create-vite): set "strict: true" in tsconfig.node.json#15820
patak-cat merged 1 commit intovitejs:mainfrom
philbates35:tsconfig-node-strict

Conversation

@philbates35
Copy link
Copy Markdown
Contributor

Description

When using @typescript-eslint/strict-type-checked rule set on a fresh Vite project and vite.config.ts is included in the files that eslint runs on, it results in the following error:

  0:1  error  This rule requires the `strictNullChecks` compiler option to be turned on to function correctly  @typescript-eslint/prefer-nullish-coalescing
  0:1  error  This rule requires the `strictNullChecks` compiler option to be turned on to function correctly  @typescript-eslint/no-unnecessary-condition

Given that we have strict enabled in the main tsconfig.json it makes sense to have it enabled here too.

Here's an example eslint.cjs to use in a fresh Vite project where you can see this error:

module.exports = {
  root: true,
  env: { browser: true, es2020: true },
  extends: [
    "eslint:recommended",
    "plugin:@typescript-eslint/strict-type-checked",
    "plugin:@typescript-eslint/stylistic-type-checked",
  ],
  parser: "@typescript-eslint/parser",
  parserOptions: {
    project: ["./tsconfig.json", "./tsconfig.node.json"],
    tsconfigRootDir: __dirname,
  },
};

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

When using @typescript-eslint/strict-type-checked rule set on a
fresh Vite project and vite.config.ts is included in the files
that eslint runs on, it results in the following error:

  0:1  error  This rule requires the `strictNullChecks` compiler option to be turned on to function correctly  @typescript-eslint/prefer-nullish-coalescing
  0:1  error  This rule requires the `strictNullChecks` compiler option to be turned on to function correctly  @typescript-eslint/no-unnecessary-condition

Given that we have "strict" enabled in the main tsconfig.json
it makes sense to have it enabled here too.
@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@philbates35 philbates35 changed the title feat(create-vite): Set "strict: true" in tsconfig.node.json feat(create-vite): set "strict: true" in tsconfig.node.json Feb 6, 2024
@patak-cat patak-cat merged commit 5e5ca7d into vitejs:main Feb 8, 2024
@philbates35 philbates35 deleted the tsconfig-node-strict branch February 8, 2024 07:08
@philbates35
Copy link
Copy Markdown
Contributor Author

Thanks for merging. @patak-dev do you think its worth me opening a separate PR to also add the following three items from tsconfig.json to tsconfig.node.json for parity?

    /* Linting */
    "strict": true,
+   "noUnusedLocals": true,
+   "noUnusedParameters": true,
+   "noFallthroughCasesInSwitch": true,

If so, are there any other additional compiler options I should copy across at the same time? I did read the documentation on references but its not clear to me which compiler options, if any, are inherited from tsconfig.json into tsconfig.node.json.

Clearly strict isn't inherited as I wouldn't have got the error using @typescript-eslint/strict-type-checked otherwise which caused me to open this PR in the first place, so I'm guessing nothing is inherited and all compiler options need to be explicitly defined in tsconfig.node.json?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants