Skip to content

Widen intersections produced by spead expressions in object literals #29081

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
ahejlsberg opened this issue Dec 18, 2018 · 0 comments
Closed
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ahejlsberg
Copy link
Member

TypeScript Version: 3.3.0-dev

Code

function test<T extends { a: string, b: string }>(obj: T): T {
    let { a, ...rest } = obj;
    return { a: 'hello', ...rest } as T;  // Error, but shouldn't be
}

Expected behavior:

No errors.

Actual behavior:

Error as shown above.

Playground Link:

https://www.typescriptlang.org/play/index.html#src=function%20test%3CT%20extends%20%7B%20a%3A%20string%2C%20b%3A%20string%20%7D%3E(obj%3A%20T)%3A%20T%20%7B%0D%0A%20%20%20%20let%20%7B%20a%2C%20...rest%20%7D%20%3D%20obj%3B%0D%0A%20%20%20%20return%20%7B%20a%3A%20'hello'%2C%20...rest%20%7D%20as%20T%3B%0D%0A%7D%0D%0A

Related Issues:

Found while investigating #28884.

@ahejlsberg ahejlsberg self-assigned this Dec 18, 2018
@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label Dec 18, 2018
@ahejlsberg ahejlsberg added this to the TypeScript 3.3 milestone Dec 18, 2018
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Dec 18, 2018
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

1 participant