镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

@syy1125

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

Metadata

Metadata

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