Skip to content

Wrong tuple inference of async IIFE return valueΒ #44992

Closed
@enisdenjo

Description

@enisdenjo

Bug Report

πŸ”Ž Search Terms

tuple, array, promise, async, function, inference

πŸ•— Version & Regression Information

v4.3.5

⏯ Playground Link

Playground link with relevant code

πŸ’» Code and behavior

// ❌ Type '(string | number)[]' is not assignable to type '[one: number, two: string]'.
const nowork: Promise<[one: number, two: string]> = (async () => {
  return [1, 'two'];
})();

πŸ™‚ Expected behavior

As with supplying an instance of Promise, correctly infer returned value as assignable to the variable.

// βœ…
const yeswork: Promise<[one: number, two: string]> = new Promise(
  (resolve) => resolve([1, 'two']),
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions