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

Disable @typescript-eslint/no-non-null-asserted-optional-chain in TS 3.9 #26

Closed
fregante opened this issue May 5, 2020 · 3 comments
Closed

Comments

@fregante
Copy link
Member

fregante commented May 5, 2020

From: https://devblogs.microsoft.com/typescript/announcing-typescript-3-9-beta/#breaking-changes

Specifically, in previous versions, the code

foo?.bar!.baz

was interpreted to be equivalent to the following JavaScript.

(foo?.bar).baz

In the above code the parentheses stop the “short-circuiting” behavior of optional chaining, so if foo is undefined, accessing baz will cause a runtime error.

@typescript-eslint/no-non-null-asserted-optional-chain made sense in that case but TS 3.9 will change the behavior to this:

foo?.bar.baz

which just evaluates to undefined when foo is undefined.

So foo?.bar!.baz becomes perfectly reasonable to catch an undefined foo but ignore an undefined foo.bar

@sindresorhus
Copy link
Member

Can you open an issue on https://github.com/typescript-eslint/typescript-eslint? It seems like the whole rule is moot then.

@fregante
Copy link
Member Author

fregante commented May 5, 2020

Done

@sindresorhus
Copy link
Member

Closing as the issues with this rule has been fixed.

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

No branches or pull requests

2 participants