You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constMISSING_DATA: null=null;exportclassTest{publicasyncget(): Promise<number|null>{constresult=awaitPromise.resolve(null);if(result===null){//error TS1059: Return expression in async function does not have a valid callable 'then' member.returnMISSING_DATA;//error TS1059: Return expression in async function does not have a valid callable 'then' member.returnPromise.resolve<null>(MISSING_DATA);// compilesreturnPromise.resolve<number|null>(MISSING_DATA);}returnPromise.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?
The text was updated successfully, but these errors were encountered:
Could be related to #5911 (comment) but my problems seems to be specific to the null type used as generic parameter for Promise and not with Promise itself
TypeScript Version: 2.1.6
Code
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 typenull
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?The text was updated successfully, but these errors were encountered: