microsoft / microsoft/TypeScript

Preserve computed property in `--isolatedDeclarations` emit

オープン
#61,892 コメント 6 件 リアクション 6 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Bug Domain: flag: isolatedDeclarations Help Wanted
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

### 🔍 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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、--isolatedDeclarations を使って動機となった例を再現し、関連する issue #60052、#58800、#58533、#60818、#61068 を確認します。computed properties に対する既存の isolated-declaration 処理を追跡します。診断が出力されず、declaration emit が関数の number 戻り値型を持つ [prop] を保持すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。