Skip to content

Support legacy TS decorators in properties without initializer #367

@octet-stream

Description

@octet-stream

Environment

Jiti: 2.4.2
Node.js: v23.7.0

Reproduction

https://github.com/octet-stream/jiti-class-properties-issue

Describe the bug

I've been working on Mikro ORM integration with jiti, so we can replace ts-node for transpilation. I decided to add jiti (among other options), because as far as I can tell - it is more compatible with tsc comparing to tsx, and this is very critical, because Mikro ORM relies on legacy decorators and emitDecoratorsMetadata as one of the options to define entities.

However, jiti fails to run code with TS legacy decorators on properties if they're not initialized (even in constructor).

Here's how typical Mikro ORM entity looks like:

import {Entity, PrimaryKey, Property} from "@mikro-orm/core"

@Entity()
export class User {
 @PrimaryKey()
 id!: number

 @Property()
 fullName!: string

 @Property()
 email!: string

 @Property()
 password!: string

 @Property({type: "text"})
 bio = ""
}

This code is valid for TS and other solutions I've been using so far. But if you import it via jiti, or run with jiti/register, you'll see following error:

node:internal/modules/run_main:104
    triggerUncaughtException(
    ^

[Error: TRANSFORM_ERROR: Definitely assigned fields cannot be initialized here, but only in the constructor
 jiti-class-properties-issue/issue.ts:0:0]

Node.js v23.7.0

Related #57
This could be the fix: #361

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions