jiti icon indicating copy to clipboard operation
jiti copied to clipboard

Typescript: Add support for class properties and emitDecoratorMetadata

Open sreuss opened this issue 3 years ago • 1 comments

Hello,

switching Typescript transpilation to jiti in Nuxt 2.15.0 has caused some problems with our code base that have prevented us from upgrading:

We are using class-validator to validate data and define our classes like this:

export class SomeModel {
  @IsString()
  @IsDefined()
  public readonly someField!: string;
}

This causes an Error: TRANSFORM_ERROR: Definitely assigned fields cannot be initialized here, but only in the constructor on Nuxt startup which can be fixed by adding @babel/plugin-proposal-class-properties to the transformation. Somehow, @babel/plugin-syntax-class-properties is already included.

In addition, we are using Nest for our serverMiddleware and have some way to utilize it's dependency injection during server side rendering. Since the dependency injection relies on emitDecoratorMetadata we'd need babel-plugin-transform-typescript-metadata to be added to the transformation.

sreuss avatar Mar 25 '22 10:03 sreuss

I am also seeing issues trying to use json2typescript on a model in a Nuxt servermiddleware. I specifically see the error about using proposal-class-properties.

ERROR Decorating class property failed. Please ensure that proposal-class-properties is enabled and runs after the decorators transform.

cshomo11 avatar Dec 02 '22 17:12 cshomo11