microsoft / microsoft/TypeScript

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

Đang mở
#42,271 0 bình luận 2 reaction 1 người được giao Xem trên GitHub

@rbuckton đang làm issue này rồi.

Từ ngày 13/1/2021.

Needs Investigation Rescheduled
Ngôn ngữ chính
Go
Star
111k
Fork
14.4k
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
117

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.