-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
bugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a lookWaiting for team members to take a look
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
type Data<T> = { value?: T };
type ValueType<TData> = TData extends Data<infer T> ? T : never;
export const foo = <TData extends Data<any>>(data: TData) => {
const getValue = () => data.value as ValueType<TData> | undefined;
const value: ValueType<TData> = getValue()!;
return value;
};
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/no-unnecessary-type-assertion": "error"
},
};
tsconfig
Expected Result
No error
Actual Result
The linter reports an error: "This assertion is unnecessary since the receiver accepts the original type of the expression."
However, if I remove the non-null assertion !
, TypeScript complains.
Additional Info
The error disappears if I change Data<any>
to Data<unknown>
in the function (foo’s) type parameter, but in my case I need it to remain any
for other reasons.
This also shows up in a real-world scenario, for example here
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a lookWaiting for team members to take a look