microsoft / microsoft/TypeScript
Compilation error when mixing promise and non promise types in promise.then's onfulfilled return type
Aperta
@rbuckton ci sta già lavorando.
Dal 13/1/2021.
Needs Investigation
Rescheduled
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.