Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Docs: [prefer-nullish-coalescing] doesn't work withstrictNullChecks: false. #5748

Labels
accepting prsGo ahead, send a pull request that resolves this issuedocumentationDocumentation ("docs") that needs adding/updatingfix: strictNullChecksissues that were fixed by turning on strictNullChecksgood first issueGood for newcomerspackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@jsalvata

Description

@jsalvata

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I havesearched for related issues and found none that matched my issue.
  • I haveread the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=4.8.4&sourceType=module&code=DYUwLgBAHgXBDOYBOBLAdgcwgHwgVzQBMQAzdEQgbgCgodcByBmoA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0WlqYSNkAC1pkA9gEMkyMswDm6KL2jjokcGAC+ILUA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylAGYBDVCXTgwAXxCygA

Repro Code

letx:string|undefined;x||'';

ESLint Config

module.exports={parser:"@typescript-eslint/parser","rules":{"@typescript-eslint/prefer-nullish-coalescing":"error"}};

tsconfig

{"compilerOptions": {"strictNullChecks":false  }}

Expected Result

An error should be reporting for the||, which should be replaced with??.

Actual Result

No error is reported.

Additional Info

The same rule works ifstrictNullChecks is changed totrue.

This makes sense becausestrictNullChecks: false essentially erases| null and| undefined from all types.

Ideally the rule should work anyway, assuming all types to be nullable. If that's not possible, a note should be added to the documentation so people do not spend a whole afternoon trying to understand why the rule doesn't work, as I did.

Versions

packageversion
@typescript-eslint/eslint-plugin5.39.0
@typescript-eslint/parser5.39.0
TypeScript4.4.4
ESLint7.32.0
node12.22.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuedocumentationDocumentation ("docs") that needs adding/updatingfix: strictNullChecksissues that were fixed by turning on strictNullChecksgood first issueGood for newcomerspackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp