-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug