You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
should not compile, as callbackfn requires a Base, not a Child. It is not correct that value is a child. If Child does not extend Base, then this causes a compile error as expected. However, if we add no explicit hierarchy between the classes, but change the example to
then the code still compiles. Both of these are errors that should hopefully be caught at compile time. It looks like typescript only checks to see if a callback parameter is valid if the classes have common members. This should be changed to a subset.
Arnav Sastry (@arknave) this is by design. It allows you to type event handler arguments easily e.g. e:MouseEvent when the original signature is only e:Event. Its allowed as long as a is subtype of b or b is subtype of a
Activity
basarat commentedon Jul 24, 2014
Arnav Sastry (@arknave) this is by design. It allows you to type event handler arguments easily e.g.
e:MouseEventwhen the original signature is onlye:Event. Its allowed as long asais subtype ofborbis subtype ofabasarat commentedon Jul 24, 2014
Arnav Sastry (@arknave) documentation : https://github.com/Microsoft/TypeScript/wiki/Type%20Compatibility#function-argument-bivariance
arknave commentedon Jul 24, 2014
Man, even the documentation agrees its unsound. Thanks for the link, not sure why I couldn't find it.