-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
TypeScript Version: 2.6.2
Code
type ItemOptions = { id?: string; };
type Item = ItemOptions & { id: string; };
type ContainerOptions = { items: ItemOptions | ItemOptions[]; };
type Container = ContainerOptions & { items: Item | Item[]; };
let c1: ContainerOptions = {
items: {
id: "1",
x: 2 // Good, error
}
}
let i1: (Item | Item[]) & (ItemOptions | ItemOptions[]) = {
id: "1",
x: 2 // Good, error
};
let c2: Container = {
items: {
id: "1",
x: 2 // Bad, no error!
},
};Expected behavior:
Compiler should notice the extraneous x object property in all 3 cases.
Actual behavior:
Compiler correctly flags "Object literal may only specify known properties" for the first 2 instances (ContainerOptions and Item union/intersection) but not the third (Container).
Related:
I'm kind of new at this whole type union/intersection thing, so it's entirely possible that the type declarations above aren't sane in the first place. If that's the case, I'd appreciate any feedback on this closely related SO question.
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created