microsoft / microsoft/TypeScript

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

Aperta
#53,626 3 commenti 1 reazione 1 assegnatario Vedi su GitHub

@rbuckton ci sta già lavorando.

Dal 10/4/2023.

Needs Investigation Rescheduled
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.