microsoft / microsoft/TypeScript

Preserve computed property in `--isolatedDeclarations` emit

未关闭
#61,892 6 条评论 6 个 reaction 已指派 0 人 在 GitHub 查看
Bug Domain: flag: isolatedDeclarations Help Wanted
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
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.

贡献指南

打开贡献指南

调研方向

首先使用 --isolatedDeclarations 重现促成该问题的示例,并查看相关 issue #60052、#58800、#58533、#60818 和 #61068。跟踪现有对计算属性的孤立声明处理;当没有 diagnostic 且 declaration emit 保留带有函数 number 返回类型的 [prop] 时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
compilers
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。