-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
π Search Terms
never bivariant method assignable generic
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about methods
β― Playground Link
π» Code
type Foo<T> = {
aMethod(t:T):void,
// strangely, simply uncommenting the next line causes the below expected error to reappear!
// aFunction:(t:T)=>void
}
declare const obj:Foo<never>
obj.aMethod(1) // Argument of type 'number' is not assignable to parameter of type 'never'
// depends on commented line
// obj.aFunction(1)
const callMethod = <T,>(a:Foo<T>, b:T)=>{
a.aMethod(b)
}
callMethod(obj, 1) // expected errorπ Actual behavior
callMethod does not issue a type warning that "Argument of type 'number' is not assignable to parameter of type 'never'".
Doing the same call outside a generic function body causes the error again.
π Expected behavior
I expect a warning, similar to if I had called the method directly or if the method were instead a function.
Additional information about the issue
Note this was originally discovered in the context of Array<never> which, when used in a generic function, allows one to unsafely push any type T: #57419 (comment).
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug