Skip to content

Typescript 4.7.3 bracketed class property compilation error strictPropertyInitialization:true #49594

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
BzenkoSergey opened this issue Jun 17, 2022 · 3 comments Β· Fixed by #49619
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@BzenkoSergey
Copy link

BzenkoSergey commented Jun 17, 2022

Bug Report

πŸ”Ž Search Terms

strictPropertyInitialization bracketed class property

πŸ•— Version & Regression Information

Typescript 4.7.3, 4.7.2

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

enum A {
  A = 'A',
  B = 'B'
}

class B {
  [A.A]: string;

  constructor() {
    this[A.A] = '1';
    this.A = '1';
    this['A'] = '1';
  }
}

πŸ™ Actual behavior

Compilation error:
Error: Property '[A.A]' has no initializer and is not definitely assigned in the constructor.

πŸ™‚ Expected behavior

Seems it should be compiled without errors.

@jcalz
Copy link
Contributor

jcalz commented Jun 17, 2022

Probably related to #45974 aka "Control-Flow Analysis for Bracketed Element Access". Could you please edit your post to fill out the bug report template to help the TS team?

@RyanCavanaugh
Copy link
Member

It works in nightly. You have the Playground set to a build that was produced before the PR was merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
3 participants