Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed
Labels
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 havesearched for related issues and found none that matched my issue.
- I haveread the FAQ and my problem is not listed.
Playground Link
Repro Code
typeObject={foo:string;}exportfunctionmyfunc<CustomObjectTextendsObject>(input:CustomObjectT):CustomObjectT{constnewObject: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 thisconstnewCustomObject=newObjectasCustomObjectT;returnnewCustomObject;}
ESLint Config
{"rules":{"@typescript-eslint/no-unsafe-type-assertion":"error"}}
tsconfig
{"compilerOptions": {"strict":true }}
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 allowableassignment according to TS, which, to my understanding, should be the heuristic used byno-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!