microsoft / microsoft/TypeScript
Wrong inference for defaulted generic in nested call
Personne n'a encore pris cette issue.
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.3k
- Merge moyen
- 2 j 4 h
- PR mergées (30 j)
- 132
Description
### 🔎 Search Terms
nested generic call inline inference contextual typing function calls default type parameter
### 🕗 Version & Regression Information
- I see the same issue from version 4.1.5 to nightly in TypeScript Playground
### ⏯ Playground Link
https://www.typescriptlang.org/play/?ts=6.0.0-dev.20260401#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwCsctUAeAFXhAA8MRVgBneRjGEgcwBp4BVK2vSYs2nHgDUBdBs1btUHeAF54AclUA+ABStYGAFzxyPIYd49GIAA4B+Q+ICUhgAYASAN7kAvh-E-3vF7OAFCgkLAIKOjYeAJW4BgU2gBuUBDIIIbkTvDu8Bg4AEIgWjTxmCDAWTnJxMDwXsHBZQlaRCRaqgASIBAQOKo8qgDqODAQwKoODgB0BcWdPX04o+OTDvAA9JvwAEZQwE1geKzwAO5YGAAWOMgYAMrWsFAFMMqExKiLvf2DaqsTKbBbbwUHwAB6Nma1HKGC0F2utweTxgLzGs3mJQAREt+gDgFiNiCODgcIdobC2p9vss-iMxoChmppnMiiVuj8cPB8VMtjsSWTgkA
### 💻 Code
```ts
declare function join(start: T, end: U, sep?: V): `${T}${V}${U}`
declare function expect(value: T): { toBe(expected: T): void }
expect(join('Hello', 'World')).toBe('HelloWorld') // bad
const withoutSeparator = join('Hello', 'World')
// ^? const withoutSeparator: "HelloWorld"
expect(withoutSeparator).toBe("HelloWorld") // good
expect(join('Hello', 'World', ' ')).toBe('Hello World') // good
```
### 🙁 Actual behavior
TypeScript does not infer the return types correctly of a nested function call when an optional generic param is omitted, even if a default is provided. When the function call is not nested, it is inferred correctly. It is also inferred correctly when all params are provided.
### 🙂 Expected behavior
I would expect that both of these approaches would compile:
```ts
expect(join('Hello', 'World')).toBe('HelloWorld') // bad
const withoutSeparator = join('Hello', 'World')
expect(withoutSeparator).toBe("HelloWorld") // good
```
### Additional information about the issue
There are very similar issues, such as #54184, #56714, and #62680 but they didn't quite match up to what I'm seeing here, particularly since the reproductions are quite a bit more complex.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par exécuter la reproduction liée dans TypeScript Playground et comparez l’appel imbriqué avec les appels autonome et entièrement spécifié. Lisez les issues associées #54184, #56714 et #62680 pour comprendre le contexte d’inférence existant. C’est terminé lorsque les deux exemples sans séparateur spécifié se compilent avec le type littéral attendu, tandis que le cas avec séparateur fourni reste correct.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript
- Domaine
- compilers
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- Calme
- Clarté
- Plutôt claire
- Accessibilité débutants
- 45/100