Skip to content

Compiler loses track of nested union types #21165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thw0rted opened this issue Jan 12, 2018 · 2 comments
Closed

Compiler loses track of nested union types #21165

thw0rted opened this issue Jan 12, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@thw0rted
Copy link

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.

@mhegazy
Copy link
Contributor

mhegazy commented Jan 12, 2018

Duplicate of #18075

@mhegazy mhegazy marked this as a duplicate of #18075 Jan 12, 2018
@mhegazy mhegazy added the Duplicate An existing issue was already created label Jan 12, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants