Microsoft/TypeScript

Type inference regression on function calls not saved to variables, due to #61668

Open

#62.071 geöffnet am 15. Juli 2025

Auf GitHub ansehen
 (1 Kommentar) (5 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
Domain: check: Type InferenceHelp WantedPossible Improvement

Repository-Metriken

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

Beschreibung

🔎 Search Terms

61668 inference overload regression tuple

🕗 Version & Regression Information

  • This changed in commit or PR #61668

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.0-beta#code/PTAEGIDYEZMgOUBjAFgQwHYHMCmBnUAFxR1AEsMAzHAJxwyVMpoHsBbUAbQwFc2AjWgBpQeQjQpYAukRagAFLwG0APmInYAlJykAoACY4kAGzR1QlHg0JkWGULkIA5PvM0AuUAAVWbMnhwAHiVBGgA+AG4DI1NzS2tbe0cAZXE3Tx92fyD1SUjokzMmKyQbO1AeAIAVHgAHYxx5QjqGz24+UJFc7CkPUAA3FjJ9KKQ7MVBa0ABeb19sgDo6PBZjfsadTQXienk3GbC5rICFtGNjeU5HFzY3ERS0zV6tnYx5Spwa+pxNKKA

💻 Code

declare function getNum(): Promise<number>;
declare function getStr(): Promise<string>;
declare function useTuple(tuple: [number, string]): void;
const p = Promise.resolve([]).then(() => Promise.all([getNum(), getStr()])).then(useTuple);

🙁 Actual behavior

The Promise.all infers to Promise<(number|string)[]>.

🙂 Expected behavior

The Promise.all should infer Promise<[number, string]>.

Additional information about the issue

This only happens when the Promise.all call is directly returned. If I instead write

const p = Promise.all([getNum(), getStr()]);
return p;

then it infers the tuple correctly again, even without doing anything that would suggest it should infer the type differently.

This PR also impacted inference of enums: in another example, I pass {mode: new Subject(Mode.A)} into a function that fails because it infers Subject<Mode.A> while if I save a temporary const mode = new Subject(Mode.A); then it infers Subject<Mode> and passes.

Contributor Guide