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 when asserting via non-null assertion operator #529

Closed
vkrol opened this issue May 14, 2019 · 2 comments · Fixed by #536
Closed
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

@vkrol
Copy link
Contributor

vkrol commented May 14, 2019

Repro
https://github.com/vkrol/typescript-eslint-no-unnecessary-type-assertion-undefined

module.exports = {
	parser: "@typescript-eslint/parser",
	parserOptions: {
		project: "tsconfig.json",
	},
	plugins: ["@typescript-eslint"],
	rules: {
		"@typescript-eslint/no-unnecessary-type-assertion": "error",
	}
};
declare function foo(str?: string): void;
declare const str: string | null;

foo(str!);

Expected Result
No errors.
Actual Result
Error:

D:\Projects\typescript-eslint-no-unnecessary-type-assertion-undefined\index.ts
  4:5  error  This assertion is unnecessary since the receiver accepts the original type of the expression  @typescript-eslint/no-unnecessary-type-assertion

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

Additional Info
The change that introduced this regression: #478.

Versions

package version
@typescript-eslint/eslint-plugin 1.9.0
@typescript-eslint/parser 1.9.0
TypeScript 3.4.5
ESLint 5.16.0
node 10.15.3
npm 6.4.1
@vkrol vkrol added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels May 14, 2019
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels May 14, 2019
@vkrol
Copy link
Contributor Author

vkrol commented May 14, 2019

@bradzacher I think that this change #478 introduced this regression.

@bradzacher
Copy link
Member

no doubt - that PR added a lot of code and additional checks and had to work around uninitialised variables (#453).

this bug only occurs when strictNullChecks is turned on.

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
2 participants