Closed
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 Object = {
foo: string;
}
export function myfunc<CustomObjectT extends Object>(input: CustomObjectT): CustomObjectT {
const newObject: Object = { foo: 'hey' };
// This is UNSAFE because CustomObjectT can/will be instantiated with a narrower subtype of Object
// no-unsafe-type-assertion should (but doesn’t) catch this
const newCustomObject = newObject as CustomObjectT;
return newCustomObject;
}
ESLint Config
{
"rules": {
"@typescript-eslint/no-unsafe-type-assertion": "error"
}
}
tsconfig
Expected Result
The line with the type assertion involving the generic parameter (newObject as CustomObjectT
) should report @typescript-eslint/no-unsafe-type-assertion
by the same logic wherein Typescript considers such a conversion unsafe:
2322: Type 'Object' is not assignable to type 'CustomObjectT'. 'Object' is assignable to the constraint of type 'CustomObjectT', but 'CustomObjectT' could be instantiated with a different subtype of constraint 'Object'.
The first example in the playground shows that this case is not an allowable assignment according to TS, which, to my understanding, should be the heuristic used by no-unsafe-type-assertion
Actual Result
No error is reported from @typescript-eslint/no-unsafe-type-assertion
Additional Info
cc @ronami
thanks for your hard work on this rule!