`--experimentalDecorators`: decorated `abstract` property is emitted as a class field (regression in 7.0)
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 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時間
- マージ済み PR(30日)
- 136
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/TypeScript のほかの issue
-
Won't Fix
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
microsoft/TypeScript#65107 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Native API: formatDiagnosticsWithColorAndContext drops related information without a file location対応中かも @timurzvural が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
microsoft/TypeScript#65087 ·
メンテナーはふだん 1 日以内に返信
-
TS7 LSP: documentHighlight returns nothing when the file path contains '@'再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン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 が 13 日前に担当しました。 オープンBug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
microsoft/TypeScript#64742 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Class names `eval` and `arguments` are not reported as invalid strict mode bindings対応中かも @dmety が 26 日前に担当しました。 オープンBug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
microsoft/TypeScript#64661 ·
メンテナーはふだん 1 日以内に返信
microsoft/TypeScript の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
Schema validation is skipped when a transaction is invoked with a lowercase first letter対応中かも @RaphaelFakhri が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
-
cmd/ebitenmobile: multi-language bindings run the complete generator twice対応中かも @kumagi が今日担当しました。 オープンos:macos performance
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
hajimehoshi/ebiten#4011 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
agent-butler-finding chore
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
jordansmall/spindrift#6318 ·
メンテナーはふだん 1 日以内に返信