Microsoft/TypeScript

Inferred type is not the same as what's passed in original generic type.

Open

#42 516 ouverte le 27 janv. 2021

Voir sur GitHub
 (6 commentaires) (0 réactions) (0 assignés)TypeScript (6 726 forks)batch import
BugDomain: check: Type InferenceEffort: DifficultHelp Wanted

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

Description

Bug Report

🔎 Search Terms

infer, generic

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions _________ and _________
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about infer.
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play?ts=4.1.3#code/C4TwDgpgBACgTgezAYQQOwM7DgVwMbAJwA8AKlALxQCGaIAfJQFBRQA+UA3lGhAO5QAFADpR1OAHMMALhp0A2gF0AlLPIAyKAgBGAKwgEoAXxbsuQ1VHImmoSFACyIAJJoAZhBKlGVchAAewBBoACYYsIgo6Fi4BETEAJbunlAAaowA-GlQsgDk-gW5TLbg0KnllEKCypSMMUkSNRyC1bU8OAC22p7KxXbQABqVTq4eJPBIqJjY+IQk5en0TEA

Playground link with relevant code

💻 Code

// The variable names are meaningless, they are simplified from vue project.
type PropConstructor<T = any> =
  | { new (...args: any[]): T & object }
  | { (): T }

type MyInfer<T> = T extends PropConstructor<infer V> ? V : 'xxx'

type VVV = (() => string) | (() => number)

type X = MyInfer<PropConstructor<VVV>>

🙁 Actual behavior

type X = (() => string) | (() => number) | ((() => string) & object) | ((() => number) & object)

🙂 Expected behavior

type X = (() => string) | (() => number))

Guide contributeur