question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getCtor returns undefined when class property refers to another class that is defined after it

See original GitHub issue

This doesn’t work,

@entity
export class Cat {
  id = 0
  toys: Toy[] = []
}

@entity
export class Toy {
  id = 0
}

const type = getType<Toy>()
await type.getCtor()  // undefined

This works,

@entity
export class Toy {
  id = 0
}

@entity
export class Cat {
  id = 0
  toys: Toy[] = []
}

const type = getType<Toy>()
await type.getCtor()  // [class Toy]

It’s the toys: Toy[] = [] line causing the issue, it works when I comment it out. It looks like it only happens for array types, Toy[]. just a direct reference works fine.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
avin-kavishcommented, Aug 7, 2022

What I did is more like this. The link is not running but I think you can check the generated code.

0reactions
Hookynscommented, Sep 29, 2022

Fixed in v1. Not in the current version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Javascript class property return undefined when called with a ...
When I call the inter method (who call countdown every 1s) this.work return undefined and I don't know why. If I call the...
Read more >
ReferenceError: reference to undefined property "x" - JavaScript
The JavaScript warning "reference to undefined property" occurs when a script attempted to access an object property which doesn't exist.
Read more >
Initialize Property Values - MATLAB & Simulink - MathWorks
Set Property Values in the Constructor. To assign a value to a property from within the class constructor, refer to the object that...
Read more >
How to use Javascript classes | Geek.I.Am
Javascript classes have always been quite different from classes that ... if (o === undefined ) return "Undefined"; return Object.prototype.
Read more >
Properties are undefined when accessed via super from ...
No, the child constructor can not access the instance until the parent constructor is complete. In this case, since both class fields define...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found