Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"design:type" return undefined if types are defined out of order #43558

Closed
abdullah2993 opened this issue Apr 6, 2021 · 4 comments
Closed

"design:type" return undefined if types are defined out of order #43558

abdullah2993 opened this issue Apr 6, 2021 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@abdullah2993
Copy link

Bug Report

Decorator metadata is not stored properly if type are not defined in right order.

import 'reflect-metadata';

function field(target: Object, propertyName: string) {}
export class C {}

export class A {
  @field
  public bb: B;

  @field
  public cc: C;

  @field
  public xx: boolean;
}

export class B {
  @field
  public aa: A;
}

console.log(Reflect.getOwnMetadata('design:type', A.prototype, 'bb')); // Return undefined expected B
console.log(Reflect.getOwnMetadata('design:type', A.prototype, 'cc'));
console.log(Reflect.getOwnMetadata('design:type', A.prototype, 'xx'));
@MartinJohns
Copy link
Contributor

Related / Duplicate: #27519

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Apr 6, 2021
@abdullah2993
Copy link
Author

This is related to #27519 but you can reproduce it without circular dependency

import 'reflect-metadata';

function field(target: Object, propertyName: string) {}

export class A {
  @field
  public bb: B;
}

export class B {}

console.log(Reflect.getOwnMetadata('design:type', A.prototype, 'bb')); // Return undefined expected B

@MartinJohns
Copy link
Contributor

MartinJohns commented Apr 6, 2021

The issue is the same: B is not declared yet when it's being used. Please read the comments in the linked issue.

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants