-
Notifications
You must be signed in to change notification settings - Fork 13.3k
TS1057: Type null is not an awaitable return type #14031
Copy link
Copy link
Closed
Description
TypeScript Version: 2.1.6
Code
const MISSING_DATA: null = null;
export class Test {
public async get(): Promise<number|null> {
const result = await Promise.resolve(null);
if (result === null) {
//error TS1059: Return expression in async function does not have a valid callable 'then' member.
return MISSING_DATA;
//error TS1059: Return expression in async function does not have a valid callable 'then' member.
return Promise.resolve<null>(MISSING_DATA);
// compiles
return Promise.resolve<number|null>(MISSING_DATA);
}
return Promise.resolve(1);
}
}Expected behavior:
Code compiles
Actual behavior:
Error error TS1059: Return expression in async function does not have a valid callable 'then' member. is thrown when returning a variable of type null
We use a constant value to indicate missing/invalid values on our data.
This constants is described with const MISSING_DATA: null = null;
When trying to return this value in a async method with the return type Promise<number|null> the mentioned error appears.
Why is null not an accepted return type for promises/async functions?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript