microsoft / microsoft/TypeScript

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

Aperta
#57,171 3 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔍 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.

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.

Direzione di ricerca

Inizia riproducendo le forme di alias di tipo accettate e la forma oggetto abstract new rifiutata nel TypeScript Playground collegato. Leggi gli esempi alla base del problema e determina come la forma oggetto dovrebbe essere analizzata e verificata dal sistema dei tipi, preservando il comportamento esistente dei membri costruttori richiamabili e non astratti. Il lavoro è completo quando la dichiarazione in forma oggetto viene accettata e si comporta in modo coerente con l'alias di tipo abstract new equivalente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.