Consider the code snippet below:
interface Contract<T> {
}
class Deal<D> implements Contract<D> {
}
class Agreement<A> implements Contract<A> {
}
Surprisingly, the following code compiles without errors:
let deal:Contract<number> = new Deal<number>()
let agreement:Contract<string> = new Agreement<string>()
// this should not compile
agreement = deal;
As well as this:
let deal:Deal<number> = new Deal<number>()
let agreement:Agreement<string> = new Agreement<string>()
// expected to fail but both compile
agreement = deal;
An accompanying playground link is provided.
The expectation was that a GenericOf<A>
would not be interchangeable with Genericof<B>
, leading to compile errors. What aspect am I misunderstanding here?