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

fix(eslint-plugin): [non-nullable-type-assertion-style] false-positive with non-nullish as assertions and types #3940

Merged
merged 2 commits into from Oct 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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