Typescript: 'async' modifier cannot be used in an ambient context.ts

Created on 24 Feb 2020  路  6Comments  路  Source: microsoft/TypeScript

TypeScript Version: 3.8.2


Search Terms: allowJs declaration 'async' modifier cannot be used in an ambient context.ts

Code
see code

when run tsc with allowJs and declaration flags enabled the code below
```TestJS.js
export class TestJS {
callAsync() {
return Promise.resolve(1);
}

async test() {
    await this.callAsync();
}

}

produce the declaretion:
```TestJS.d.ts
export class TestJS {
    callAsync(): Promise<number>;
    async test(): Promise<void>; --> error
}

but when a try to use this class I receive 'async' modifier cannot be used in an ambient context.ts(1040)

Expected behavior:
the TestJS.d.ts shouldn't contain async

Actual behavior:
TestJS.d.ts conteins async

Playground Link: code

Related Issues:

Declaration Emit JavaScript checkJs good first issue help wanted

All 6 comments

was going to post about this right now, the behavior from JS / TS is definitely off

Tests should probably include a test for generators too.

with typescript 3.7.5 work well

Seems like this is fixed in the nightlies. @weswigham can you verify, track down the fix, and cherry-pick it?

Seems like this is fixed in the nightlies.

This issue related to the method makeSerializePropertySymbol. In the 3.8.*_(need to find the commit where it was done)_ was added the way to get the modifier flags const modifierFlags = getDeclarationModifierFlagsFromSymbol(p); of a symbol and use these flags to create nodes. The 3.7.* handles only static modifier const staticFlag = isStatic ? ModifierFlags.Static : 0; - that's why 3.7.* doesn't emit async modifier.

cc @DanielRosenwasser @weswigham @francesc79

@a-tarasyuk it regressed in https://github.com/microsoft/TypeScript/pull/35731 probably, since prior to that we weren't pulling on "original" modifier flags from anywhere.

Seems like this is fixed in the nightlies

Looks broken in the nightlies to me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wmaurer picture wmaurer  路  3Comments

CyrusNajmabadi picture CyrusNajmabadi  路  3Comments

dlaberge picture dlaberge  路  3Comments

siddjain picture siddjain  路  3Comments

blendsdk picture blendsdk  路  3Comments