-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
TypeScript 1.8.9
I'm trying to understand how to correctly type a rejected promise. I expect the following code to compile.
const bar: Promise<number> =
Promise.resolve(1)
.then(() => Promise.reject<string>(new Error('foo')))Error:
main.ts(7,7): error TS2322: Type 'Promise<string>' is not assignable to type 'Promise<number>'.
Type 'string' is not assignable to type 'number'.
Is it possible to have different types for a Promise when it is rejected and fulfilled?
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code