`--experimentalDecorators`: decorated `abstract` property is emitted as a class field (regression in 7.0)
维护者通常 1 天内回复
已经有一个关联 PR 被合并了。
- #64982 来自 @1-DARK —— 已合并
评估
- 难度
- 4/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- typescript
- 领域
- compilers
调研方向
Start by reading typeeraser.go around the decorated declare and abstract property handling, then follow visitPropertyDeclaration in legacydecorators.go to see why the preserved node emits a field. Compare with the visitPropertyDeclaration handling in ts.ts described in the issue. Done means the abstract property is erased while its legacy decorator call remains, matching the expected output; an open pull request is already linked.
由索引模型根据 Issue 内容生成。
描述
🔎 Search Terms
experimentalDecorators, abstract property, decorator, class field, useDefineForClassFields, typeeraser, legacy decorators
🕗 Version & Regression Information
- Regression from tsc 6.0.3, which erases the field.
- Reproduces in 7.0.2, 7.1.0-beta and 7.1.0-dev.20261026.1.
💻 Code
function dec(target: object, key: string) {
Object.defineProperty(target, key, { get: () => 'from prototype', configurable: true });
}
abstract class Base {
@dec abstract data: string;
}
class Sub extends Base {
declare data: string;
}
const s = new Sub();
console.log(Object.hasOwn(s, 'data'), s.data);
{ "compilerOptions": { "target": "es2022", "experimentalDecorators": true } }
🙁 Actual behavior
Base gets a data; field, so every instance has an own data: undefined that shadows whatever the decorator put on the prototype. Prints true undefined.
class Base {
data;
}
__decorate([
dec
], Base.prototype, "data", void 0);
🙂 Expected behavior
Same as tsc 6.0.3: the field is erased and only the __decorate call remains. Prints false from prototype.
class Base {
}
__decorate([
dec
], Base.prototype, "data", void 0);
Additional information about the issue
The field appears only when all three hold: experimentalDecorators, a decorator on the abstract property, and define semantics (useDefineForClassFields, the default at target ES2022 and later). emitDecoratorMetadata makes no difference. An undecorated abstract property and a decorated declare property are both still erased.
The likely cause is in typeeraser.go. For a decorated declare/abstract property under experimentalDecorators, it keeps the node so that LegacyDecoratorsTransformer can emit the __decorate call. But it rebuilds the node with VisitModifiers, which elides AbstractKeyword. visitPropertyDeclaration in legacydecorators.go then finds neither NodeFlagsAmbient nor ModifierFlagsAbstract and emits a field. declare escapes this because the node keeps NodeFlagsAmbient. Strada's visitPropertyDeclaration in ts.ts handles the same case by appending a declare modifier to the preserved node (concatenate(modifiers, factory.createModifiersFromModifierFlags(ModifierFlags.Ambient))).
We hit this in TypeORM entities: an abstract base declares a decorated abstract column, each subclass redeclares it with declare, and every entity instance gains an own data: undefined it doesn't have under tsc 6.
- 主要语言
- Go
- 星标
- 112k
- 派生
- 15.4k
- 平均合并
- 3 天 1 小时
- 30 天内合并 PR
- 136
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/TypeScript 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
microsoft/TypeScript#65290 ·
维护者通常 1 天内回复
-
Native API: formatDiagnosticsWithColorAndContext drops related information without a file location可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
microsoft/TypeScript#65087 ·
维护者通常 1 天内回复
-
TS7 LSP: documentHighlight returns nothing when the file path contains '@'可能重新可做 关联的 PR 已关闭且未合并。 未关闭Bug
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/TypeScript#64758 ·
维护者通常 1 天内回复
-
Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`可能已有人在做 @rajnish-verma-22172 于 14 天前认领。 未关闭Bug
难度 2/5 1-3 小时 新手友好度 76/100
microsoft/TypeScript#64742 · 1 条评论 ·
维护者通常 1 天内回复
-
Non-enum CLI options with multiple values separated by comma and space aren't whitespace trimmed可能已有人在做 @RyanCavanaugh 于 28 天前认领。 未关闭Bug
难度 2/5 1-3 小时 新手友好度 68/100
microsoft/TypeScript#64618 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 microsoft/TypeScript 的全部 Issue
相似的 Issue
-
mqtt_paho: transformer.DeleteExtension and DeleteAttribute make WritePubMessage fail可能已有人在做 @RaphaelFakhri 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 86/100
cloudevents/sdk-go#1349 ·
-
getChaosHub always returns totalFaults "0"可能已有人在做 @Aryanbhargava18 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
litmuschaos/litmus#5710 ·
维护者通常 3 天内回复
-
vtselect: data race in Tempo search tags APIs for invalid TraceQL queries可能已有人在做 @Shubham19032004 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
VictoriaMetrics/VictoriaTraces#304 ·
维护者通常 1 天内回复
-
kn secret create --tls-cert creates the certificate under the wrong key可能已有人在做 @RaphaelFakhri 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 91/100
维护者通常 1 天内回复
-
Routing rule or circuit breaker trip expression with an unknown CEL function hangs daprd可能已有人在做 @RaphaelFakhri 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复