Skip to content

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

Open

Description

@shicks

πŸ”Ž Search Terms

61668 inference overload regression tuple

πŸ•— Version & Regression Information

⏯ 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.

Activity

  1. added
    Possible Improvement
    on Jul 15, 2025
  2. jcrang commented on Jul 28, 2025

    @jcrang

    I think we're hitting the same issue. We've been able to work around it by using as const. In the example code that's:

    - const p = Promise.resolve([]).then(() => Promise.all([getNum(), getStr()])).then(useTuple);
    + const p = Promise.resolve([]).then(() => Promise.all([getNum(), getStr()] as const)).then(useTuple);

    In our case we own the function where inference isn't working as expected so have been able to use a const
    type parameter
    .

  3. added
    Domain: check: Type Inference
    on Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: check: Type InferencePossible Improvement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ Proxy