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

[no-unnecessary-type-assertion] False positive with null/undefined union type #1061

Closed
codebutler opened this issue Oct 9, 2019 · 1 comment · Fixed by #1002
Closed

[no-unnecessary-type-assertion] False positive with null/undefined union type #1061

codebutler opened this issue Oct 9, 2019 · 1 comment · Fixed by #1002
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@codebutler
Copy link

Looks like the fix for #529 did not cover all edge cases.

{
  "rules": {
      "@typescript-eslint/no-unnecessary-type-assertion": "error",
  }
}
const optionalNonNull = (s?: string) => { };
let s: string | null | undefined;

/*
Argument of type 'string | null | undefined' is not assignable to parameter of type 'string | undefined'.
  Type 'null' is not assignable to type 'string | undefined'.
*/
optionalNonNull(s);

/*
This assertion is unnecessary since the receiver accepts the original type of the expression.
*/
optionalNonNull(s!);

Expected Result

Should not trigger an error.

Actual Result

Triggers an error.

Additional Info

N/A

Versions

"@typescript-eslint/eslint-plugin": "^2.3.3",

Also tested with master 054df27

@codebutler codebutler added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Oct 9, 2019
@bradzacher bradzacher added bug Something isn't working has pr there is a PR raised to close this and removed triage Waiting for maintainers to take a look labels Oct 10, 2019
@bradzacher
Copy link
Member

#1002 fixes this

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants