Skip to content

[no-unnecessary-type-assertion] false positive when asserting the result of generic function invocation #528

Closed
@vkrol

Description

@vkrol

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

module.exports = {
	parser: "@typescript-eslint/parser",
	parserOptions: {
		project: "tsconfig.json",
	},
	plugins: ["@typescript-eslint"],
	rules: {
		"@typescript-eslint/no-unnecessary-type-assertion": "error",
	}
};
declare function foo<T extends Element = Element>(): T;
const a = (foo() as HTMLInputElement).value;

Expected Result
No errors.
Actual Result
Error:

D:\Projects\typescript-eslint-no-unnecessary-type-assertion-generic-function\index.ts
  2:12  error  This assertion is unnecessary since it does not change the 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
N/A.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingexternalThis issue is with another package, not typescript-eslint itselfpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions