Skip to content

Computed property names not emitted if containing class is not transformed #21544

Closed

Description

TypeScript Version: master (df15d5b)

I stumbled upon TypeScript's behavior of emitting computed property names declared in classes that might have side effects, and I learned from #19430 that this is intentional. But it looks like the names only get emitted if the containing class has some other characteristic that triggers the TypeScript transformer, and I believe that is not intended.

Search Terms: computed property names class transform emit

Code
Compile with: tsc --target es6 a.ts b.ts

// a.ts
export const x = Symbol();
export const y = Symbol();

// b.ts
import * as a from './a';

class NotTransformed {
  [a.x]: number;
}

class Transformed {
  transformMe = 5;
  [a.y]: number;
}

Expected behavior: b.js contains both a.x and a.y.

Actual behavior: b.js contains a.y but not a.x.

Playground Link: Link. This is a different example using namespaces (which I know is legacy) because the playground doesn't support multiple files.

Related Issues: #19430

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugFixed

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions