Skip to content

Inferred return type of a generic function with destructure incorrectly retains generics #33823

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
syy1125 opened this issue Oct 4, 2019 · 0 comments · Fixed by #34826
Closed
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@syy1125
Copy link

syy1125 commented Oct 4, 2019

TypeScript Version: 3.6.3, 3.7-Beta

Search Terms:

  • generic function infer return type
  • generic function destructure

Code

Minimal reproducible example:

interface TestGeneric<TG> {
  f: string
  g: TG
}

const removeF = <TX>({ f, ...rest }: TestGeneric<TX>) => {
  return rest
}

const result: number = removeF<number>({ f: '', g: 3 }).g

Expected behavior:

No type errors

Actual behavior:

Type 'TX' is not assignable to type 'number'

Playground Link:
https://www.typescriptlang.org/play/index.html?ts=3.7-Beta&ssl=10&ssc=58&pln=1&pc=1#code/JYOwLgpgTgZghgYwgAgCoQM5gOIRNYBAHlWwD5kBvAWAChlkYAuZLKUAczoY5dLoC+dOggD2ILMigQAtqIBuEAGLIAvMhIANMgApKjADTIAdKemSBfTDjwFiqbQEo1FGvSkQwAVyggPWQWFaMQkwfy8AGzAWEC8ZACNoNQ85RSUiWIToXX1mZAByfKNeZABmZAFHYy5aIA

Related Issues: #33579 #28234

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

Successfully merging a pull request may close this issue.

3 participants