Skip to content

Restrict spreading for Instantiable Type with non object constraint#31185

Merged
orta merged 2 commits intomicrosoft:masterfrom
collin5:b30851
Aug 15, 2019
Merged

Restrict spreading for Instantiable Type with non object constraint#31185
orta merged 2 commits intomicrosoft:masterfrom
collin5:b30851

Conversation

@collin5
Copy link
Copy Markdown
Contributor

@collin5 collin5 commented May 1, 2019

i.e

function f1<T extends number>(arg: T) {
  return { ...arg }; // should error "Spread types may only be created from object types."
}

function f2<T extends number | { [key: string]: any }>(arg: T) {
  return { ...arg } // should also error
}

#30851 - Partially resolves

@collin5 collin5 changed the title Check for valid spread type on TypeVariable Check for valid spread type on TypeVariable constraint May 1, 2019
Comment thread src/compiler/checker.ts Outdated
Comment thread src/compiler/checker.ts Outdated
@collin5 collin5 changed the title Check for valid spread type on TypeVariable constraint Restrict spreading for non object Instantiable Type constraint May 3, 2019
@collin5 collin5 changed the title Restrict spreading for non object Instantiable Type constraint Restrict spreading for Instantiable Type with non object constraint May 3, 2019
@collin5
Copy link
Copy Markdown
Contributor Author

collin5 commented May 3, 2019

Updated!

@orta
Copy link
Copy Markdown
Contributor

orta commented Aug 15, 2019

Yep, this looks good to me - thanks @collin5. let's get this is. I've commented in #30851 about unknown being something we're open to having a PR closing 👍

@orta orta merged commit 6cd8bcd into microsoft:master Aug 15, 2019
@collin5
Copy link
Copy Markdown
Contributor Author

collin5 commented Aug 15, 2019

Thank you.

@collin5 collin5 deleted the b30851 branch August 15, 2019 21:28
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants