microsoft / microsoft/TypeScript

Adding a compilerOption to disable error on property override accessor in 4.0.beta

Offen
#39,401 6 Kommentare 17 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

Search Terms

property override accessor

Suggestion

Previously in 3.9, property can override an accessor with no emit errors. And in 4.0 beta, a break change was introduced by #33509.

It's reasonable to report an error on property override accessor in most case, but I'm using experimentalDecorators to inject a property accessor in prototype.

Currently I cannot find a solution for this use case, so I'm suggesting to add a new compilerOption to disable this check(strictOnly?) for compatibility.

Use Cases

class Animal {
    private _age: number
    get age(){ return this._age }
    set age(value){ this._age = value }
}

class Dog extends Animal {
    @defaultValue(100) age: number;     // Unexpected error here
}

function defaultValue(value) {
    return (obj, name) => {
        Object.defineProperty(obj, name, {
            get() { return value }
        })
    }
}

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, dieses Issue zusammen mit der in #33509 referenzierten Breaking Change zu lesen und zu überprüfen, wie Compileroptionen sowie Diagnosen zu Überschreibungen von Properties/Accessors behandelt werden. Das Issue nennt keine Dateien oder Tests; für die Erledigung wäre eine abgestimmte Kompatibilitätsoption erforderlich, die diese Diagnose unterdrückt, ohne das erzeugte JavaScript zu ändern, sowie eine Abdeckung für das Decorator-Beispiel.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
28/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.