microsoft / microsoft/TypeScript

Allow `interface extends object` syntax

Aperta
#60,730 2 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

In Discussion Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

🔍 Search Terms

interface extends object

✅ Viability Checklist
⭐ Suggestion

I propose to allow the following syntax:

interface MyInterface extends object {}

This would have identical semantics to the following (currently legal) syntax:

type _object = object
interface MyInterface extends _object {}

Details:

  1. No primitive may be assigned to such an interface or an intersection containing such an interface
  2. This requirement is inherited by any extending interfaces

I'm requesting this feature mainly because it was the only pain-point mentioned in this related issue. To quote:

No one is going to turn on this behavior if it means every time they write

interface Person {
  name: string
}

they actually need to write

interface _PersonFields {
  name: string;
}
type Person = object & _PersonFields;

Regardless of the outcome of that other issue however, it would be nice to be able to extends object without going through that kind of hassle.

📃 Motivating Example

A small usability improvement to allow interfaces to more easily declare that primitives cannot be assigned to them.

💻 Use Cases
  1. What do you want to use this for? To avoid non-idiomatic verbosity
  2. What shortcomings exist with current approaches? Non-idiomatic verbosity
  3. What workarounds are you using in the meantime? Non-idiomatic verbosity

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 esaminando la sintassi proposta interface extends object e la issue correlata #60582. Poiché non sono indicati file di implementazione o test, traccia la gestione pertinente dell’ereditarietà delle interfacce e dell’assegnabilità prima di definire i test per la semantica dichiarata dell’assegnazione di valori primitivi.

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

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
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.