Skip to content

Spread syntax with extends object type parameters #20510

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
ethanresnick opened this issue Dec 6, 2017 · 1 comment
Closed

Spread syntax with extends object type parameters #20510

ethanresnick opened this issue Dec 6, 2017 · 1 comment
Assignees
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@ethanresnick
Copy link
Contributor

TypeScript Version: 2.6.1

Code

function<T extends object>(it: T) {
    return { ...it };
}

Expected behavior:
No error

Actual behavior:
Error: Spread types may only be created from object types.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Dec 6, 2017
@sandersn
Copy link
Member

sandersn commented Dec 7, 2017

T is a type parameter, which cannot be used to create a spread type. The object type constraint doesn't get around this rule.

If we ever add a first-class spread type this restriction will go away.

@sandersn sandersn added the Working as Intended The behavior described is the intended behavior; this is not a bug label Dec 7, 2017
@sandersn sandersn closed this as completed Dec 7, 2017
@mhegazy mhegazy removed the Bug A bug in TypeScript label Jan 11, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants