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

Nested constructor produces unhelpful function union #12

Closed
samhh opened this issue Sep 13, 2021 · 2 comments · Fixed by #18
Closed

Nested constructor produces unhelpful function union #12

samhh opened this issue Sep 13, 2021 · 2 comments · Fixed by #18

Comments

@samhh
Copy link
Member

samhh commented Sep 13, 2021

type A = Member<'A1', string> | Member<'A2', number>
type B = Member<'B1', A>

const { B1 } = create<B>()
declare const x: A
B1(x)
Diagnostics:
1. Argument of type 'A' is not assignable to parameter of type 'never'.
  The intersection 'Member<"A1", string> & Member<"A2", number>' was reduced to 'never' because property '[tagKey]' has conflicting types in some constituents.
    Type 'Member<"A1", string>' is not assignable to type 'never'.
@samhh
Copy link
Member Author

samhh commented Sep 13, 2021

The type of B1:

// What it is
const B1: ((x: Member<"A1", string>) => B) | ((x:  Member<"A2", number>) => B)

// What it needs to be
const B1: (x: A) => B

@samhh
Copy link
Member Author

samhh commented Sep 13, 2021

The conditional type in Constructor is distributing over the union B. It can be solved by changing the condition from B extends undefined to [B] extends [undefined], per this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant