microsoft / microsoft/TypeScript

Class properties cannot be initialized within constructor if the property key comes from a static class property (e.g. [Symbol.iterator])

オープン
#53,626 コメント 3 件 リアクション 1 件 担当者 1 名 GitHub で見る

@rbuckton がすでに取り組んでいます。

2023年4月10日 から。

Needs Investigation Rescheduled
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

Bug Report

🔎 Search Terms

symbol property constructor 2564

🕗 Version & Regression Information
  • This changed between versions 4.6.4 and 4.7.4
⏯ Playground Link

Playground link with relevant code

💻 Code
const standaloneSymbol = Symbol("standalone");

class SymbolClass {
    static readonly staticSymbol = Symbol("static");
}

interface IHaveSymbols {
    [standaloneSymbol]: number;
    [SymbolClass.staticSymbol]: number;
}

class HavePropertyInitializedSymbols implements IHaveSymbols {
    [standaloneSymbol] = 1;
    [SymbolClass.staticSymbol] = 2;
}

class HaveOverriddenSymbols extends HavePropertyInitializedSymbols {
    constructor() {
        super();
        this[standaloneSymbol] = 3;
        this[SymbolClass.staticSymbol] = 4;
    }
}

class HaveConstructorInitializedSymbols implements IHaveSymbols {
    [standaloneSymbol]: number;
    [SymbolClass.staticSymbol]: number;
    constructor() {
        this[standaloneSymbol] = 3;
        this[SymbolClass.staticSymbol] = 4;
    }
}
🙁 Actual behavior
Property '[SymbolClass.staticSymbol]' has no initializer and is not definitely assigned in the constructor.(2564)
(property) SymbolClass.staticSymbol: typeof SymbolClass.staticSymbol

It's wrong because the property is definitely assigned in the constructor

🙂 Expected behavior

No error, because the property is definitely assigned in the constructor

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

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

はじめの一歩

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

評価

この issue はまだ評価されていません。

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

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