microsoft / microsoft/TypeScript

Compilation error when mixing promise and non promise types in promise.then's onfulfilled return type

Open
#42,271 0 comments 2 reactions 1 assignee View on GitHub

@rbuckton is already working on this.

Since Jan 13, 2021.

Needs Investigation Rescheduled
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Bug Report

🔎 Search Terms

typescript compilation error on mix promise and non promise type in promise context

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

Playground link with relevant code

💻 Code
Promise.resolve(true)
	.then(result => result && Promise.resolve("hello"))
	.then(something => console.log(something));
🙁 Actual behavior

Got a compilation error:

    Argument of type '(result: boolean) => false | Promise<string>' is not assignable to parameter of type '(value: boolean) => string | PromiseLike<string>'. Type 'false | Promise<string>' is not assignable to type 'string | PromiseLike<string>'. Type 'boolean' is not assignable to type 'string | PromiseLike<string>'.

And something was inferred as boolean.

🙂 Expected behavior

No compilation error and something should have been inferred as boolean | string.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.