microsoft / microsoft/TypeScript

Missing computed properties in declaration emit

Open
#61,068 1 comment 0 reactions 0 assignees View on GitHub
In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

With #60052, we now emit qualified names rather than generate an index signature for computed names in classes; however, this now puts us in an awkward place where regardless of errors, declaration emit diverges on `isolatedDeclarations`.

Playground Links:

* [5.7, without `isolatedDeclarations`](https://www.typescriptlang.org/play/?isolatedDeclarations=false&ts=5.7.3#code/KYDwDg9gTgLgBAYwgOwM7wOZWMGBLZDALjgFdk8BHU4OVATwFsAjCAGzgF44BlJ1tgAoAlAG4AUKEixEKdLPIwS5KjTr92XXhqFjxk8NHgI2AQ1So4AWXoBhMxYCMcAN7i4HuAG0sOfIQBdEnQoAgwtACIAd2g2ABMIiU9vJEUguGRSFmAoLQAWACYJAF99KSM4YEzGOAAFKAgwHJh6ADlTRmBLN2TfXDDIvv8MCIAad09U5HhuCKmYMfFSg2ljB0sbe3NUAtcJjy96xua2jq6AOiGw9JCB2ZioeMT97yOm2FPO1HP59OrmHL5IpLMqGGRsXBwMANMAAQmCMFChAkKwqJm21js6wAzHtkl5oY10iIuAA+OAANwgeDiWhJnHJLlKpSAA)
* [Nightly, without `isolatedDeclarations`](https://www.typescriptlang.org/play/?isolatedDeclarations=false&ts=5.8.0-dev.20250128#code/KYDwDg9gTgLgBAYwgOwM7wOZWMGBLZDALjgFdk8BHU4OVATwFsAjCAGzgF44BlJ1tgAoAlAG4AUKEixEKdLPIwS5KjTr92XXhqFjxk8NHgI2AQ1So4AWXoBhMxYCMcAN7i4HuAG0sOfIQBdEnQoAgwtACIAd2g2ABMIiU9vJEUguGRSFmAoLQAWACYJAF99KSM4YEzGOAAFKAgwHJh6ADlTRmBLN2TfXDDIvv8MCIAad09U5HhuCKmYMfFSg2ljB0sbe3NUAtcJjy96xua2jq6AOiGw9JCB2ZioeMT97yOm2FPO1HP59OrmHL5IpLMqGGRsXBwMANMAAQmCMFChAkKwqJm21js6wAzHtkl5oY10iIuAA+OAANwgeDiWhJnHJLlKpSAA)
* [Nightly, with `isolatedDeclarations`](https://www.typescriptlang.org/play/?isolatedDeclarations=true&ts=5.8.0-dev.20250128#code/KYDwDg9gTgLgBAYwgOwM7wOZWMGBLZDALjgFdk8BHU4OVATwFsAjCAGzgF44BlJ1tgAoAlAG4AUKEixEKdLPIwS5KjTr92XXhqFjxk8NHgI2AQ1So4AWXoBhMxYCMcAN7i4HuAG0sOfIQBdEnQoAgwtACIAd2g2ABMIiU9vJEUguGRSFmAoLQAWACYJAF99KSM4YEzGOAAFKAgwHJh6ADlTRmBLN2TfXDDIvv8MCIAad09U5HhuCKmYMfFSg2ljB0sbe3NUAtcJjy96xua2jq6AOiGw9JCB2ZioeMT97yOm2FPO1HP59OrmHL5IpLMqGGRsXBwMANMAAQmCMFChAkKwqJm21js6wAzHtkl5oY10iIuAA+OAANwgeDiWhJnHJLlKpSAA)

```ts
export const greeting: unique symbol = Symbol();
export const count: unique symbol = Symbol();

export class MyClass1 {
[greeting]: string = "world";
[count]: number = 42;
}

export enum PropertyNames {
greeting = "greeting",
count = "count",
}

export class MyClass2 {
[PropertyNames.greeting]: string = "world";
[PropertyNames.count]: number = 42;
}

export let prop!: string;

export class MyClass3 {
[prop]: () => void = () => {}
}
```

Compared to `--isolatedDeclarations false` The declaration emit lacks expected contents in `MyClass1` and `MyClass2`:

```diff lang=ts
export declare const greeting: unique symbol;
export declare const count: unique symbol;
export declare class MyClass1 {
- [greeting]: string;
- [count]: number;
}
export declare enum PropertyNames {
greeting = "greeting",
count = "count"
}
export declare class MyClass2 {
- [PropertyNames.greeting]: string;
- [PropertyNames.count]: number;
}
export declare let prop: string;
export declare class MyClass3 {
[prop]: () => void;
}
```

It is surprising that `prop` is emitted regardless of `--isolatedDeclarations`, but not the other contents.

Contributor guide

Open the contributing guide

Research direction

Start with the TypeScript declaration emit behavior shown in the Playground links, comparing output with and without --isolatedDeclarations for MyClass1, MyClass2, and MyClass3. Trace computed property handling and make declaration emit retain the expected computed properties while preserving the current prop behavior; verify the emitted declaration diff against the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.