- Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" instead
Description
Hi
I stumbled on a strange behaviour which in my understanding is a bug (in Node with Typescript 1.6 and reproduced in the online Playground)
B is a subclass of A
It is possible to assign a variable F of type "function with A argument" with a value "function with a B argument".
This means that when calling F with a value of type A, the concrete function called will use some specific properties of B which are missing, leading to a runtime error
Olivier
classMammal{}classWhaleextendsMammal{swim(duration:number){/* some code */}}functionswim10(w:Whale){w.swim(10);}typemammalFunc=(m:Mammal)=>void;functioneach(m:Mammal[],f:(Mammal)=>void){m.forEach(f);}varf1:mammalFunc=swim10;// Problem : this should not be possiblevarm1=newMammal();f1(m1);// this compiles, but will fail at runtime because m1 has no swim() methodeach([m1],swim10);// this compiles, but will also fail at runtimeMetadata
Metadata
Assignees
Labels
By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" instead