Skip to content

'async' modifier cannot be used in an ambient context.ts #36989

Closed

Description

@francesc79

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

export class TestJS {
    callAsync() {
        return Promise.resolve(1);
    }

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

produce the declaretion:

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:

Activity

  1. pocesar commented on Feb 25, 2020

    @pocesar

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

  2. DanielRosenwasser commented on Feb 25, 2020

    @DanielRosenwasser
    Member

    Tests should probably include a test for generators too.

  3. francesc79 commented on Feb 25, 2020

    @francesc79
    Author

    with typescript 3.7.5 work well

  4. DanielRosenwasser commented on Feb 25, 2020

    @DanielRosenwasser
    Member

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

  5. a-tarasyuk commented on Feb 26, 2020

    @a-tarasyuk
    Contributor

    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 Daniel Rosenwasser (@DanielRosenwasser) Wesley Wigham (@weswigham) zazos (@francesc79)

  6. weswigham commented on Feb 27, 2020

    @weswigham
    Member

    Oleksandr Tarasiuk (@a-tarasyuk) it regressed in #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

  7. added a commit that references this issue on Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Domain: Declaration EmitThe issue relates to the emission of d.ts filesDomain: JavaScriptThe issue relates to JavaScript specificallyGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do thischeckJsRelates to checking JavaScript using TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions