Skip to content

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

Closed

Description

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

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions