Skip to content

A type unified by conditional types loses some types #29945

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
falsandtru opened this issue Feb 17, 2019 · 0 comments · Fixed by #30010
Closed

A type unified by conditional types loses some types #29945

falsandtru opened this issue Feb 17, 2019 · 0 comments · Fixed by #30010
Assignees
Labels
Bug A bug in TypeScript

Comments

@falsandtru
Copy link
Contributor

falsandtru commented Feb 17, 2019

TypeScript Version: 3.4.0-dev.201xxxxx

Search Terms:

Code

export type ElChildren =
  | ElChildren.Void
  | ElChildren.Text;
export namespace ElChildren {
  export type Void = undefined;
  export type Text = string;
}

type Relax<C extends ElChildren> = C extends ElChildren.Text ? ElChildren.Text : C;

export class Elem<
  C extends ElChildren,
  > {
  constructor(
    private children_: Relax<C>,
  ) {
  }
}

new Elem(undefined as ElChildren.Void);
new Elem('' as ElChildren.Text);
new Elem('' as ElChildren.Void | ElChildren.Text); // error
new Elem('' as ElChildren); // error

Expected behavior:

pass

Actual behavior:

Argument of type 'ElChildren' is not assignable to parameter of type 'undefined'.
  Type 'string' is not assignable to type 'undefined'.

Playground Link: http://www.typescriptlang.org/play/index.html#src=export%20type%20ElChildren%20%3D%0D%0A%20%20%7C%20ElChildren.Void%0D%0A%20%20%7C%20ElChildren.Text%3B%0D%0Aexport%20namespace%20ElChildren%20%7B%0D%0A%20%20export%20type%20Void%20%3D%20undefined%3B%0D%0A%20%20export%20type%20Text%20%3D%20string%3B%0D%0A%7D%0D%0A%0D%0Atype%20Relax%3CC%20extends%20ElChildren%3E%20%3D%20C%20extends%20ElChildren.Text%20%3F%20ElChildren.Text%20%3A%20C%3B%0D%0A%0D%0Aexport%20class%20Elem%3C%0D%0A%20%20C%20extends%20ElChildren%2C%0D%0A%20%20%3E%20%7B%0D%0A%20%20constructor(%0D%0A%20%20%20%20private%20children_%3A%20Relax%3CC%3E%2C%0D%0A%20%20)%20%7B%0D%0A%20%20%7D%0D%0A%7D%0D%0A%0D%0Anew%20Elem(undefined%20as%20ElChildren.Void)%3B%0D%0Anew%20Elem(''%20as%20ElChildren.Text)%3B%0D%0Anew%20Elem(''%20as%20ElChildren.Void%20%7C%20ElChildren.Text)%3B%0D%0Anew%20Elem(''%20as%20ElChildren)%3B

Related Issues:

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Feb 19, 2019
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants