microsoft / microsoft/TypeScript

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

Abierto
#42,271 0 comentarios 2 reacciones 1 asignado Ver en GitHub

@rbuckton ya está trabajando en esto.

Desde el 13/1/2021.

Needs Investigation Rescheduled
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.