When using a generic wrapper around some kind of known state, I ran into incompatible type errors when casting a child to its parent. The idea being that if Tomato
extends Fruit
, then Wrapper<Tomato>
as Wrapper<Fruit>
ought to work.
interface Wrapper<TProps> {
// This next line is correct
mergeWith<K extends keyof TProps>(merger: (key: K) => any): void;
update<K extends keyof TProps>(updater: (value: TProps[K]) => any): void;
}
interface BrokenWrapper<TProps> {
// Somehow this next line seems identical to mergeWith above
mergeWith(merger: (key: keyof TProps) => any): void;
update<K extends keyof TProps>(updater: (value: TProps[K]) => any): void;
}