no-unnecessary-assertion
Added in v0.9.4Configuration
rslint.config.ts
Rule Details
When using TypeScript, runtime assertions based on types can often be omitted provided that the types are accurate.
This rule warns when you do an assertion about being null, undefined, or NaN on something that cannot be those types, as that indicates either the assertion can be removed or the types need to be adjusted. It checks toBeNull, toBeUndefined, toBeDefined and toBeNaN, with or without .not; assertions using .resolves or .rejects are not checked.
This rule requires type information. It reports a configuration warning when the strictNullChecks compiler option is disabled, because without it no type can rule out null or undefined.
Examples of incorrect code for this rule:
Examples of correct code for this rule: