Microsoft/TypeScript

Infinite type instantiation around recursive conditional types

Open

#60.237 geöffnet am 15. Okt. 2024

Auf GitHub ansehen
 (1 Kommentar) (1 Reaktion) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
BugDomain: check: Type CircularityHelp Wanted

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

🔎 Search Terms

infinite type instantiation excessively deep recursive conditional

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about infinite and recursive types.

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.6.3#code/C4TwDgpgBAggPARQDRQMoD4oF4oKhAD2AgDsATAZygG8oBDALnpJCgF8oB+WRAbQCI6-ALooMUJiQgA3CACcA3ACglASxLE5AMzoBjaACE4AFUzUlUKFsToAFAEcmCAJRN4yKKeVsVoSFABhbCgjajZMQmJyKiN1LXkoAA1MbkSJKClZRV9waDScIMjSSmZWbmA5AFdoJh0AGwoIZSA

💻 Code

type A<Q, S> = Q extends { a: any } ? A<Q["a"], S> : never;

interface B<T> {
  f<Q>(q: Q): A<Q, T>;
}

type C = B<{}> extends B<infer X> ? X : never;

type X = C extends any ? true : false;
//       ~ Type instantiation is excessively deep and possibly infinite.(2589) 

🙁 Actual behavior

The last line errors out.

🙂 Expected behavior

The code should pass the type check.

Additional information about the issue

An alternative way to get the same error: https://www.typescriptlang.org/play/?ts=5.6.3#code/C4TwDgpgBAggPARQDRQMoD4oF4oKhAD2AgDsATAZygG8oBDALnpJCgF8oB+WRAbQCI6-ALooMUJiQgA3CACcA3ACglASxLE5AMzoBjaACE4AFUzUlUKFsToAFAEcmCAJRN4yKKeVsVZCLoAbOjloLQBXEl1gVQB7EigAWzoAawgjU1tgJmNXKHT0ZSU-QODQiKjY+OsMrM9c6RjVMkLrI2o2dDsk1INbEjCAgPoqOhZhmjZnZ2UgA

Contributor Guide