microsoft / microsoft/TypeScript

Per-decorator opt-in for type metadata emit

Aperta
#54,493 1 commento 0 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

Suggestion

Emit type metadata only for decorators that need it.

🔍 Search Terms

decorator metadata

✅ Viability 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, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Note: This might be non-viable under the checklist because it require type-based emit, but type metadata for decorators is already type-based emit, so maybe this is an area where it's ok...

Currently, the emitDecoratorMetadata flag emits metadata for every decorated field, even though many decorators might not need that metadata, which can cause bloat.

The compiler could instead look at some statically available metadata about the decorator itself, so that the decorator can opt-in to type metadata. This opt-in could be part of the type of the decorator function, ie you have to cast the decorator to a type that signals the decorator needs metadata:

const property = (options): ClassAccessorDecoratorWithMetadata => (target, context) => { /* ... */ };

📃 Motivating Example

Any program that uses a combination of decorators that need type metadata and those that don't.

💻 Use Cases

Workarounds are difficult here. Maybe developers can create separate projects and try to isolate those that require type metadata, but that might not always be possible - there might be single files that uses both decorators that require type-metadata and decorators that don't.

cc @rbuckton

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 leggendo l’issue #54493 e tracciando il percorso del compilatore per l’opzione esistente emitDecoratorMetadata; il report non indica file sorgente, punti di ingresso o test. Per considerare il lavoro completato servirebbero un design concordato per l’opt-in per decoratore, l’implementazione e test che coprano i decoratori che richiedono e quelli che non richiedono metadati di tipo.

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
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.