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 over generics inconsistency #31340

Closed
bluescreen303 opened this issue May 10, 2019 · 4 comments
Closed

union type over generics inconsistency #31340

bluescreen303 opened this issue May 10, 2019 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@bluescreen303
Copy link

TypeScript Version: 3.5.0-dev.20190508

Search Terms: union generics

Code

type Foo1 = (e: string) => { bar: number, name: string } | { bar: number, label: string }
function t1(foo: Foo1): number {
    return foo("hello").bar + 1
}

type Foo2 = ((e: string) => { bar: number, name: string }) | ((e: string) => { bar: number, label: string })
function t2(foo: Foo2): number {
    return foo("hello").bar + 1
}
type Foo3 = <E>(e: E) => { bar: number, name: E } | { bar: number, label: E }
function t3(foo: Foo3): number {
    return foo("hello").bar + 1
}

type Foo4 = (<E>(e: E) => { bar: number, name: E }) | (<E>(e: E) => { bar: number, label: E })
function t4(foo: Foo4): number {
    return foo("hello").bar + 1
}

Expected behavior:
I would expect t4 to work, because it is just a combination of t2 and t3, which both work.
Clearly, typescript is able to process over function types in a union and isn't blocked by functions that have a generic type parameter.

Actual behavior:

error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'Foo4' has no compatible call signatures.
@jack-williams
Copy link
Collaborator

I think this is a current design limitation. Call signatures are not synthesized for unions of generic functions. See here.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 13, 2019
@RyanCavanaugh
Copy link
Member

Thanks @jack-williams for link to #7294

@jack-williams
Copy link
Collaborator

No problem @RyanCavanaugh!

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

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

4 participants