Skip to content
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

Union type does not work as expected when recursive types and array is used #24403

Closed
pleerock opened this issue May 25, 2018 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@pleerock
Copy link

Having following definition:

interface Post {
    id: number;
    title: string;
    tags: {
        id: number;
        name: string;
    };
}

type WhereOptions<E> = {
    [P in keyof E]?: E[P] extends object ? WhereOptions<E[P]> : E[P]
};

type Options<E> = {
    where?: WhereOptions<E> | WhereOptions<E>[];
};

const options: Options<Post> = {
  where: {
      id: 1,
      tags: {
          id: 1,
          blabla: 1, // compiles fine, but I expect it say missing property blabla
      }
  }
};

I don't have compiler errors as I expect.

If I change Options interface to:

type Options<E> = {
    where?: WhereOptions<E>; // | WhereOptions<E>[];
};

Then I see the error I expect. Is it a bug?

(sorry as usual don't know how to title issue).

@pleerock pleerock changed the title Union type does not work as expected when array is used Union type does not work as expected when recursive types and array is used May 25, 2018
@mhegazy
Copy link
Contributor

mhegazy commented May 25, 2018

looks like a duplicate of #20863

@mhegazy mhegazy added the Duplicate An existing issue was already created label May 25, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants