microsoft / microsoft/TypeScript

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

オープン
#42,271 コメント 0 件 リアクション 2 件 担当者 1 名 GitHub で見る

@rbuckton がすでに取り組んでいます。

2021年1月13日 から。

Needs Investigation Rescheduled
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。