-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed as not planned
Closed as not planned
Copy link
Labels
package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-pluginworking as intendedIssues that are closed as they are working as intendedIssues that are closed as they are working as intended
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Playground Link
Repro Code
const foo = document.body.querySelector(
'#myelement > div',
) as HTMLElement | null; // This assertion is unnecessary since it does not change the type of the expression.
if (foo)
foo.style.display = '';
const bar = document.body.querySelector(
'#myelement > div',
);
if (bar)
bar.style.display = ''; // failes because Element has no `style`
const baz = document.body.querySelector<HTMLElement>(
'#myelement > div',
);
if (baz)
baz.style.display = '';
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/no-unnecessary-type-assertion": "error"
},
};
tsconfig
Expected Result
First example should not complain because the assertion changes the type.
Actual Result
There is an error "This assertion is unnecessary since it does not change the type of the expression." at the first example.
Additional Info
No response
Metadata
Metadata
Assignees
Labels
package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-pluginworking as intendedIssues that are closed as they are working as intendedIssues that are closed as they are working as intended