Skip to content

Docs: [prefer-optional-chain] update docs for the option allowPotentiallyUnsafeFixesThatModifyTheReturnTypeIKnowWhatImDoing #7702

@cigui

Description

@cigui

Before You File a Documentation Request Please Confirm You Have Done The Following...

Suggested Changes

The doc for the option allowPotentiallyUnsafeFixesThatModifyTheReturnTypeIKnowWhatImDoing in the rule prefer-optional-chain seems to provide incorrect examples. The original code goes following:

declare const foo: { bar: boolean } | null | undefined;
declare function acceptsBoolean(arg: boolean): void;

// ✅ typechecks succesfully as the expression only returns `boolean`
acceptsBoolean(foo != null && foo.bar);

// ❌ typechecks UNSUCCESSFULLY as the expression returns `boolean | undefined`
acceptsBoolean(foo != null && foo.bar);

But the two lines calling acceptsBoolean are equal. It seems like a copy-paste error. I think the second line should be acceptsBoolean(foo?.bar) perhaps?

Affected URL(s)

https://typescript-eslint.io/rules/prefer-optional-chain/#allowpotentiallyunsafefixesthatmodifythereturntypeiknowwhatimdoing

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuedocumentationDocumentation ("docs") that needs adding/updatinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions