-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
Description
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 have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Playground Link
Repro Code
function f(a?: { b: string | null }): void {
if (a !== undefined && a.b !== null) {
console.log(a.b)
}
}ESLint Config
module.exports = {
"rules": {
"@typescript-eslint/prefer-optional-chain": "error"
}
}tsconfig
Expected Result
No fix.
Actual Result
prefer-optional-chain produces this fix:
function f(a?: { b: string | null }): void {
- if (a !== undefined && a.b !== null) {
+ if (a?.b !== null) {
console.log(a.b)
}
}This is unsound because if a is undefined, then a?.b is undefined, not null.
Additional Info
No response
Metadata
Metadata
Assignees
Labels
accepting prsGo ahead, send a pull request that resolves this issueGo ahead, send a pull request that resolves this issuebugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
{ "compilerOptions": { "strict": true } }