Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 8, 2024

Conversation

philbates35
Copy link
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.
Copy link

stackblitz bot commented Feb 6, 2024

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-dev patak-dev merged commit 5e5ca7d into vitejs:main Feb 8, 2024
9 of 11 checks passed
@philbates35 philbates35 deleted the tsconfig-node-strict branch February 8, 2024 07:08
@philbates35
Copy link
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.

None yet

3 participants