Skip to content

Typescript: Add support for class properties and emitDecoratorMetadata #57

@sreuss

Description

@sreuss

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions