microsoft / microsoft/TypeScript

Generic conditional type prematurely resolves to one of the branches instead of deferring

Aperta
#57,650 6 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@ahejlsberg ci sta già lavorando.

Dal 6/3/2024.

Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 Search Terms

generic, conditional, premature / eager / defer, inline,

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about generic conditional types
⏯ Playground Link

Playground link

💻 Code
type IsNumber<T> = [T] extends [number] ? true : false
type IsFalse<T extends boolean> = false[] extends T[] ? true : false

type Direct = IsFalse<IsNumber<string>> extends true ? 0 : 1;
//   ^? type Direct = 0

type Shortcut<T> = IsFalse<IsNumber<T>> extends true ? 0 : 1;
type Indirect = Shortcut<string>;
//   ^? type Indirect = 1

🙁 Actual behavior

Direct and Indirect are different.

🙂 Expected behavior

Direct and Indirect should be the same because Direct is just an inlined version of Shortcut<string>.

Additional information about the issue

This feels like a similar issue to #39364, #30708, #30020 and maybe some others, but many of those have been resolved already and yet this one remains. Came from this Stack Overflow question.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.