Skip to content

public static fields without initializer are removed even with useDefineForClassFields=true #61671

Open
@sapphi-red

Description

@sapphi-red

πŸ”Ž Search Terms

static class field, useDefineForClassFields

πŸ•— Version & Regression Information

This bug exists at least with v3.7.5 and v5.8.3.

⏯ Playground Link

https://www.typescriptlang.org/play/?useDefineForClassFields=true&jsx=0&ts=5.8.3#code/MYGwhgzhAEBiD29oG8BQ1oQC5iwS2GgDNEAuaAVwDsATAUyLyrpoG5V1ph4rsAnCsCzw+ACgCUKThm694IOgDoQ8AOaiA5CXgboTOInGcAvqlPMA7gfgTUQA

πŸ’» Code

class Foo {
  static foo: undefined;

  constructor() {
    console.log('foo' in Foo)
  }
}
new Foo()

πŸ™ Actual behavior

console.log('foo' in Foo) outputs false after transformed.

πŸ™‚ Expected behavior

console.log('foo' in Foo) to output true after transformed. Because removing : undefined from the input and running that outputs true.

Additional information about the issue

esbuild, babel, SWC transforms correctly (esbuild try, babel repl, SWC playground)

Private static fields works fine (TS playground).

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions