microsoft / microsoft/TypeScript

Allow `abstract` modifier on construct signature in object type literal

Offen
#57,171 3 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Awaiting More Feedback Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

🔍 Search Terms

'abstract' modifier cannot appear on a type member

✅ Viability Checklist
⭐ Suggestion

Allow using abstract new … constructor definition keywords in an interface, i.e. in an object form (i.e., within curly braces).

📃 Motivating Example

Consider possible definitions of:

  • a function (a callable object),
  • a non-abstract constructor,
  • an abstract constructor.

All of those definitions can be created through type aliasing:

type Callable = () => void // ✅
type Constructor = new () => void // ✅
type ConstructorAbstract = abstract new () => void // ✅

But only the first two definitions can be created using an object form:

type Callable = { (): void } // ✅
type Constructor = { new (): void } // ✅
type ConstructorAbstract = { abstract new (): void } // ❌
//                           ^^^^^^^^
// Error: 'abstract' modifier cannot appear on a type member

Try it.

Apparently, in this form the token new is considered a method name, rather than a keyword.

I suggest making the last one a valid expression by parsing new as a keyword.

💻 Use Cases

This suggestion is mainly for visual consistency, there is no functional change sought to be. To the folks who prefer using interfaces whenever possible (like me), the requirement of using type here is somewhat unreasonable, although it doesn't pose any significant problems.

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, die akzeptierten Typalias-Formen und die abgelehnte Objektform abstract new im verlinkten TypeScript Playground zu reproduzieren. Lies die zugrunde liegenden Beispiele und bestimme, wie die Objektform geparst und typgeprüft werden sollte, wobei das bestehende Verhalten von aufrufbaren und nicht-abstrakten Konstruktor-Membern erhalten bleibt. Die Aufgabe ist erledigt, wenn die Deklaration in Objektform akzeptiert wird und sich konsistent mit dem äquivalenten abstract new-Typalias verhält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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