TypeScript Version: 2.1.5
interface Orig<T extends string> {
type: T;
}
type TypeId = 'SpecA';
interface SpecA extends Orig<TypeId> {
name?: string;
}
const goodCast = <SpecA>{
type: 'SpecA'
}
const badCast = <SpecA>{
type: 'SpecB'
}
// throws an error:
// Type '{ type: "SpecB"; }' cannot be converted to type 'SpecA'.
// Types of property 'type' are incompatible.
// Type '"SpecB"' is not comparable to type '"SpecA"'.
const justData = {
type: 'SpecB'
};
const castLater = <SpecA>justData;
// Expected an error to be thrown, but the compiler accepts this.
Expected behavior:
The typecast to castLater should trigger a compile error.
Actual behavior:
it doesn't.
TypeScript Version: 2.1.5
Expected behavior:
The typecast to
castLatershould trigger a compile error.Actual behavior:
it doesn't.