-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Update: I submitted a bad code sample the first time around — I've updated this to reflect something that seems actually broken.
--
TypeScript Version: 2.5.2
Code
interface ThingTypeOne {
type: 'one';
}
interface ThingTypeTwo {
type: 'two';
}
type ThingType = 'one' | 'two';
type Thing = ThingTypeOne | ThingTypeTwo;
function makeNewThing(thingType: ThingType): Thing {
return {
type: thingType
};
}
Expected behavior:
No error
Actual behavior:
foo.ts(14,3): error TS2322: Type '{ type: ThingType; }' is not assignable to type 'Thing'.
Type '{ type: ThingType; }' is not assignable to type 'ThingTypeTwo'.
Types of property 'type' are incompatible.
Type 'ThingType' is not assignable to type '"two"'.
Type '"one"' is not assignable to type '"two"'.
It looks to me like the issue is that the compiler doesn't figure out the union of keys within the interfaces. If that's true, it seems strange to me that this is a breaking error since this code should work just fine.
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