microsoft / microsoft/TypeScript

Preserve computed property in `--isolatedDeclarations` emit

Offen
#61,892 6 Kommentare 6 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bug Domain: flag: isolatedDeclarations Help Wanted
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

### 🔍 Search Terms

isolated declarations, computed properties

### ✅ Viability Checklist

- [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [x] This wouldn't change the runtime behavior of existing JavaScript code
- [x] This could be implemented without emitting different JS based on the types of the expressions
- [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- [x] This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- [x] This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals

### ⭐ Suggestion

Now that #60052 allows for (some) computed properties in in `.d.ts` files I think the next step is for `--isolatedDeclaration` to be updated to not error and to emit the computed properties. Opening this issue if helpful to track this work.

I believe the previous plan (#58800) to introduce a new syntactic marker is no longer required.

Related issues: #58533 #60818 #61068

### 📃 Motivating Example

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

export class MyClass {
[prop] = () => Math.random();
}
```

### `@isolatedDeclarations: false`

[playground](https://www.typescriptlang.org/play/?isolatedDeclarations=false&ts=5.8.3#code/PTAEAEEsGcHsBsCGAXApgEwCKoMZIE4qSwB20AXKAGaLzSoBQqAHgA6z7Kg6nRev5YrSgFcSkAI4jUoaAE8AtgCMEoALygAyopXwAFAEoA3AyZsOXPImjRQAWTkBhJDdABvBqC+gA2gKEAuuqghuoAfPYoABYAdIQk6LAKhiYAvgxAA)

```ts
export declare const prop: unique symbol;
export declare class MyClass {
[prop]: () => number;
}
```

### `@isolatedDeclarations: true` (current 🙁)

[playground](https://www.typescriptlang.org/play/?isolatedDeclarations=true&ts=5.8.3#code/PTAEAEEsGcHsBsCGAXApgEwCKoMZIE4qSwB20AXKMvgK6oBQqAHgA6z7Kg6nScv6wWlGiUgBHOqGgBPALYAjBKAC8oAMpzF8ABQBKANz1GrdpzyJo0UAFlpAYSSXQAb3qh3oANr9BAXRWgeioAfDYoABYAdIQk6LCyeoYAvvRAA)

```sh
ts(9038) Computed property names on class or object literals cannot be inferred with --isolatedDeclarations.
```

```ts
export declare const prop: unique symbol;
export declare class MyClass {
}
```

### `@isolatedDeclarations: true` (future 🚀 )

No error and same emit as `@isolatedDeclarations: false`

```ts
export declare const prop: unique symbol;
export declare class MyClass {
[prop]: () => number;
}
```

### 💻 Use Cases

The primary use case is enabling isolated declarations at scale on large codebases that make heavy use of computed properties.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, das motivierende Beispiel mit --isolatedDeclarations zu reproduzieren, und prüfe die verwandten Issues #60052, #58800, #58533, #60818 und #61068. Verfolge die bestehende Verarbeitung isolierter Deklarationen für berechnete Eigenschaften; abgeschlossen ist die Aufgabe, wenn keine Diagnose ausgegeben wird und der Declaration Emit [prop] mit dem number-Rückgabetyp der Funktion bewahrt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.