microsoft / microsoft/TypeScript

Expose MappedType in typescript.d.ts

Aperta
#59,221 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

🔍 Search Terms

mappedtype interface typeParameter constraintType templateType

✅ Viability Checklist
⭐ Suggestion

Coming over from typescript-eslint, we need to look at the properties on mapped types for the @typescript-eslint/no-unnecessary-type-parameters ("Golden Rule of Generics") rule. But, MappedType is marked as @internal in TypeScript's definition:

https://github.com/microsoft/TypeScript/blob/22bbe867fd4b86e2187270f6c284e6cfd92a3fea/src/compiler/types.ts#L6584-L6594

Could we have that interface be public, please? Even if all the fields other than constraintType, templateType, and typeParameter are switched to @internal. I don't know of a more sanctioned way to access those type properties. Is there one?

📃 Motivating Example

Marking MappedType as public would provide a way for type checker API consumers to reason about mapped types.

💻 Use Cases

See https://github.com/typescript-eslint/typescript-eslint/pull/8173 & https://github.com/typescript-eslint/typescript-eslint/pull/9530: in typescript-eslint, we need to access a few properties of mapped types to check if they're uses of a type parameter. We ended up writing our own interface MappedType extends ts.ObjectType:

interface MappedType extends ts.ObjectType {
  typeParameter?: ts.Type; // #8173
  constraintType?: ts.Type; // #9530
  templateType?: ts.Type; // #9530
}

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 da src/compiler/types.ts, intorno all’interfaccia interna MappedType, e confronta i suoi campi attuali con l’API pubblica richiesta. Esamina gli esempi collegati delle regole typescript-eslint per comprendere le esigenze dei consumer. Il lavoro è completato quando MappedType viene esposto tramite typescript.d.ts con l’accesso richiesto a typeParameter, constraintType e templateType.

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

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.