Skip to content

TS1057: Type null is not an awaitable return type #14031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lukas-zech-software opened this issue Feb 13, 2017 · 2 comments
Closed

TS1057: Type null is not an awaitable return type #14031

lukas-zech-software opened this issue Feb 13, 2017 · 2 comments
Assignees
Labels
Bug A bug in TypeScript

Comments

@lukas-zech-software
Copy link

lukas-zech-software commented Feb 13, 2017

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?

@lukas-zech-software
Copy link
Author

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

@mhegazy mhegazy added the Bug A bug in TypeScript label Feb 13, 2017
@rbuckton
Copy link
Contributor

This does not repro in 2.3. It looks like it may have been fixed by #13134.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants