Typescript: On static method Error TS2339: Property 'then' does not exist on type '() => Promise'

Created on 5 Aug 2016  路  5Comments  路  Source: microsoft/TypeScript

TypeScript Version: 1.8.10 and nightly (2.1.0-dev.20160804)

Code

/// <reference path="typings/globals/core-js/index.d.ts" />

export class CryptoService
{
  static getToken()
  {
    return Promise.resolve('123');
  }

  static setXsrf()
  {
    return this.getToken.then( token  => {} );
  }
}

Not expected error:

error TS2339: Property 'then' does not exist on type '() => Promise'.

Question

Most helpful comment

Unless you have reason to believe there's actually a compiler bug, please use Stack Overflow for questions or log an issue with the definition file. Thanks!

All 5 comments

You wanted to write this.getToken() (notice the ()) right?

@DickvdBrink, you say that I can not get a token?

Change:
return this.getToken.then( token => {} );
to
return this.getToken().then( token => {} );

Thank you guys! I am ashamed =)

Unless you have reason to believe there's actually a compiler bug, please use Stack Overflow for questions or log an issue with the definition file. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MartynasZilinskas picture MartynasZilinskas  路  3Comments

seanzer picture seanzer  路  3Comments

CyrusNajmabadi picture CyrusNajmabadi  路  3Comments

wmaurer picture wmaurer  路  3Comments

jbondc picture jbondc  路  3Comments