Skip to content

3.4 regression on type inference with union typed array spreads #30720

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
mceachen opened this issue Apr 2, 2019 · 3 comments
Closed

3.4 regression on type inference with union typed array spreads #30720

mceachen opened this issue Apr 2, 2019 · 3 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@mceachen
Copy link

mceachen commented Apr 2, 2019

Reproduced with TS 3.4.1 and [email protected].

Search Terms:

Union typed array spreads used to work with TS 3.3 but require explicit types with TS 3.4.

Code

Works as expected on both 3.3 and 3.4:

declare function concat<T>(...args: (T | T[])[]): T[]
concat([1, 2, 3], 4)

Works on 3.3, breaks under 3.4 and @next:

export type Maybe<T> = T | undefined
declare function concatMaybe<T>(...args: (Maybe<T> | Maybe<T>[])[]): T[]

concatMaybe([1, 2, 3], 4)

Unexpected error

error TS2345: Argument of type '4' is not assignable to parameter of type 'number[] | (number[] | undefined)[] | undefined'.

This does compile under 3.4, fwiw:

concatMaybe<number>([1, 2, 3], 4)

Related Issues:

#30694

@mceachen mceachen changed the title 3.4 regression on type inference with array spread types 3.4 regression on type inference with union typed array spreads Apr 2, 2019
@ahejlsberg ahejlsberg self-assigned this Apr 3, 2019
@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label Apr 3, 2019
@ahejlsberg ahejlsberg added this to the TypeScript 3.4.1 milestone Apr 3, 2019
@mceachen
Copy link
Author

mceachen commented Apr 3, 2019

@ahejlsberg I don't know if you and your team get this enough, but THANK YOU FOR TYPESCRIPT!

You and your team are doing great work. Kudos!

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Apr 7, 2019
@ahejlsberg
Copy link
Member

@mceachen Thanks, much appreciated!

@craigkovatch
Copy link

For real, TypeScript is the closest I have ever felt to expressing thought into code at the speed I can think it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants