Skip to content

Classes passed to decorators dont work when there circular references used in those classes #4521

Closed
@pleerock

Description

@pleerock

First I thought the problem in reflect-metadata component I used, but now I think the issue is with typescript decorators themself. I described that issue there: microsoft/reflect-metadata#12

You can understand what is problem from my code out run output:

import {Person} from "./Person";
import {Relation} from "./Relation";

export class PersonInfo {
    @Relation(Person)
    info: string;
}
import {Relation} from "./Relation";
import {PersonInfo} from "./PersonInfo";

export class Person {
    name: string;
    @Relation(PersonInfo)
    info: string;
}
export function Relation(cls) {
    return function () {
        console.log(cls);
    }
}
import {Person} from "./Person";
let person = new Person();

result:

undefined
[Function: PersonInfo]

expected result:

[Function: Person]
[Function: PersonInfo]

From generated sources I found that Person_1.Person is undefined here:

    __decorate([
        Relation_1.Relation(Person_1.Person), 
        __metadata('design:type', String)
    ], PersonInfo.prototype, "info");

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions