Skip to content

Commit

Permalink
fix(eslint-plugin): [non-nullable-type-assertion-style] false-positiv…
Browse files Browse the repository at this point in the history
…e with non-nullish `as` assertions and types (#3940)
  • Loading branch information
FloEdelmann committed Oct 3, 2021
1 parent c40dd13 commit 40760f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Expand Up @@ -57,6 +57,10 @@ export default util.createRule({
type.flags !== ts.TypeFlags.Undefined,
);

if (nonNullishOriginalTypes.length === originalTypes.length) {
return false;
}

for (const assertedType of assertedTypes) {
if (!nonNullishOriginalTypes.includes(assertedType)) {
return false;
Expand Down
Expand Up @@ -54,6 +54,13 @@ const y = x as NonNullable<T>;
`
const foo = [] as const;
`,
`
const x = 1 as 1;
`,
`
declare function foo<T = any>(): T;
const bar = foo() as number;
`,
],

invalid: [
Expand Down

0 comments on commit 40760f9

Please sign in to comment.