microsoft / microsoft/TypeScript

Expose serializers from TypeScript transformer (ts.ts)

Ouverte
#17,516 10 commentaires 5 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Domain: API Needs Proposal Suggestion
Langage dominant
Go
Étoiles
111k
Forks
14.3k
Merge moyen
2 j 4 h
PR mergées (30 j)
132

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par src/compiler/transformers/ts.ts et la Transform API, puis examinez TransformationContext.getEmitResolver() et l’utilisation de EmitResolver décrite dans l’issue. Déterminez la limite de l’API publique nécessaire pour réutiliser la sérialisation des types dans des transformateurs personnalisés, et vérifiez que les types de paramètres tels que MyInterface sont sérialisés en Object sans nécessiter un second Program.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
typescript
Domaine
compilers
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
30/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.