microsoft / microsoft/TypeScript

Expose serializers from TypeScript transformer (ts.ts)

Abierto
#17,516 10 comentarios 5 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Domain: API Needs Proposal Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con src/compiler/transformers/ts.ts y la Transform API; después, inspecciona TransformationContext.getEmitResolver() y el uso de EmitResolver descrito en el issue. Determina el límite de la API pública necesario para reutilizar la serialización de tipos en transformadores personalizados y verifica que los tipos de parámetros como MyInterface se serialicen como Object sin requerir un segundo Program.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.