Closed zpdDG4gta8XKpMCd closed 9 years ago
That is by design. For purposes of assignment compatibility, parameters in signatures are bi-variant. We do this more by necessity than choice. There is good discussion of the issue in #1394. As @RyanCavanaugh points out in that thread, without this rule Array<Dog>
wouldn't be a structural subtype of Array<Animal>
.
@ahejlsberg, this is a very sad news to me, we are not using array methods (they are commented out in our lib.d.ts), is there a way to detect this pattern in code using compiler API?
@aleksey-bykov See #274. It's definitely possible to change the compiler's behavior to disallow this, and we've considered it already as you can see in that issue. It would simply need to be opt in behavior or else it breaks too much existing code (including core JS idioms).
Not sure if this one relates to #3038
Can seen at playground: link