Skip to content

Commit 40760f9

Browse files
authored
fix(eslint-plugin): [non-nullable-type-assertion-style] false-positive with non-nullish as assertions and types (typescript-eslint#3940)
1 parent c40dd13 commit 40760f9

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export default util.createRule({
5757
type.flags !== ts.TypeFlags.Undefined,
5858
);
5959

60+
if (nonNullishOriginalTypes.length === originalTypes.length) {
61+
return false;
62+
}
63+
6064
for (const assertedType of assertedTypes) {
6165
if (!nonNullishOriginalTypes.includes(assertedType)) {
6266
return false;

packages/eslint-plugin/tests/rules/non-nullable-type-assertion-style.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ const y = x as NonNullable<T>;
5454
`
5555
const foo = [] as const;
5656
`,
57+
`
58+
const x = 1 as 1;
59+
`,
60+
`
61+
declare function foo<T = any>(): T;
62+
const bar = foo() as number;
63+
`,
5764
],
5865

5966
invalid: [

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy