microsoft / microsoft/TypeScript
Expose serializers from TypeScript transformer (ts.ts)
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
With the introduction of the Transform API some of the logic in transformers/ts.ts needs to be exposed. (and maybe from other places...)
I'll explain by example:
@SomeDecorator()
export class MyClass {
constructor(public myInterface: MyInterface, public myClass: MyOtherClass) {}
}
If I want to transform the code so all parameter type metadata will be on a static property of the class. (this is angular DI)
@SomeDecorator()
export class MyClass {
constructor(public myInterface: MyInterface, public myClass: MyOtherClass) { }
static ctorParams: [Object, MyOtherClass];
}
This operation is currently impossible.
To get the right identifier for each type I need to serialize the type with some logic so MyInterface will become Object since it's not really a value.
The native TypeScript transformer has a lot of code for handling the logic of type serialization and it's not something one will want to copy, its huge.
Even if someone decided to replicate the logic, there's not access to the EmitResolver which is the "type checker" used by the native transformer to serialize the types.
TransformationContext.getEmitResolver() is @internal
The workaround is to actually run another Program process to get access to a TypeChecker.
It's not even possible to get a hold of the current running Program instance since TransformerFactory does not get access to it.
Is it possible to expose the serializatoin logic in the TypeScript transformer? I know it's complex, recursing and state dependant (scope) but it seems like not being able to serialize a type to create a literal is something basic
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da src/compiler/transformers/ts.ts e dalla Transform API, quindi esamina TransformationContext.getEmitResolver() e l’utilizzo di EmitResolver descritto nell’issue. Determina il confine dell’API pubblica necessario per riutilizzare la serializzazione dei tipi nei transformer personalizzati e verifica che i tipi dei parametri come MyInterface vengano serializzati come Object senza richiedere un secondo Program.
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