Rule suggestion: flag non-null assertion applied to an optional chain #1398
Labels
enhancement: new plugin rule
New rule request for eslint-plugin
has pr
there is a PR raised to close this
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
The optional chain operator is built such that it will return
undefined
if there is a nullish member.Ending an optional chain expression with a non-null assertion is blatantly incorrect, and leads to type safety holes in your code, which will likely lead to runtime errors.
It is much better to either hoist the non-null assertion up the chain, so the thing you "know" is nullish is asserted on, instead of the entire expression.
The text was updated successfully, but these errors were encountered: