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

Maybe enable prefer-nullish-coalescing and prefer-optional-chain #2121

Open
ShadowJonathan opened this issue Jan 23, 2022 · 2 comments
Open

Comments

@ShadowJonathan
Copy link
Contributor

https://typescript-eslint.io/rules/prefer-nullish-coalescing/

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

These discourage falsy/truthy checking, and actually check for undefined or null.

This'd help if a parameter is number | null/idx?: number, to not branch on 0.

@turt2live
Copy link
Member

Why?

@ShadowJonathan
Copy link
Contributor Author

As explained in #2124, truthy/falsy values can lead to subtle bugs, and while the other issue deals with enforcing the abstention of using it in expressions, this issue converts any such case where a && a.b && a.b.c && a.b.c.d happens, and instead suggests to coalece it to a?.b?.c?.d, while not checking for truthy values inbetween, but explicitly for nullability.

Enabling it would help developers to more ergonomically and correctly write code that works with nullable variables, properties, functions, etc.

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

3 participants