Skip to content

Await in static field initializer #43099

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
Kingwl opened this issue Mar 5, 2021 · 5 comments
Closed

Await in static field initializer #43099

Kingwl opened this issue Mar 5, 2021 · 5 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@Kingwl
Copy link
Contributor

Kingwl commented Mar 5, 2021

Bug Report

πŸ”Ž Search Terms

πŸ•— Version & Regression Information

  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground

πŸ’» Code

async function f () {
  class C {
    static a = await (Promise.resolve(1)) // error here
  }
  return C as any
}

f().then(c => {
  console.log(c.a) 
})

πŸ™ Actual behavior

ReferenceError: await is not defined when target below es2020

πŸ™‚ Expected behavior

No error at wait.
Output: 1

@Kingwl
Copy link
Contributor Author

Kingwl commented Mar 5, 2021

/cc: @sandersn @rbuckton

@Kingwl
Copy link
Contributor Author

Kingwl commented Mar 5, 2021

Any suggestions? Happy to work on these too.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 5, 2021
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 5, 2021
@Kingwl
Copy link
Contributor Author

Kingwl commented Mar 6, 2021

staticFieldDefinition[?Yield, ?Await]

from https://tc39.es/proposal-static-class-features/#prod-ClassElement

And

const initializer = doOutsideOfContext(NodeFlags.YieldContext | NodeFlags.AwaitContext | NodeFlags.DisallowInContext, parseInitializer);

In parsePropertyDeclaration.

@Kingwl
Copy link
Contributor Author

Kingwl commented Mar 8, 2021

Holy shit. I have confused about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants