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
interfaceA{x: string;}interfaceB{x: string;y: string;}functioncopyB(value: B): B{returnundefined;}varvalues: A[]=[];values.map(value=>copyB(value))// fails as expectedvalues.map(copyB);// <-- expected to fail, but it does not
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
The text was updated successfully, but these errors were encountered: