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.

Constructor(Type.ctor) type problems

See original GitHub issue

Not sure if this is a known issue or not, was going to figure a way to fix it if so. Also saw some TODO in the code, so I’m not sure if you have some issues in mind etc.

This is my TS:

import {SomeServiceClass} from "./tests/Classes/ControllerSetup/SomeServiceClass";
import {getType} from "tst-reflect";

const someServiceClass = getType<SomeServiceClass>();

const ctor = someServiceClass.ctor;

const t = Reflect.construct(ctor, []);

This is the generated JS:

"use strict";
Object.defineProperty(exports, "__esModule", {value : true});
const tst_reflect_1 = require("tst-reflect");
(0, tst_reflect_1.getType)({
	k     : 0,
	n     : "SomeServiceInterface",
	fn    : "@envuso/container/src/tests/Classes/ControllerSetup/SomeServiceInterface.ts:SomeServiceInterface#21493",
	props : [{n : "propertyName", t : (0, tst_reflect_1.getType)({n : "string", k : 2}), am : 2, acs : 0, ro : false, o : false}],
	meths : [{n : "randomMethod", params : [], rt : (0, tst_reflect_1.getType)({n : "any", k : 2}), tp : [], o : false, am : 2}],
}, 21493);
(0, tst_reflect_1.getType)({
	k     : 1,
	n     : "SomeServiceClass",
	fn    : "@envuso/container/src/tests/Classes/ControllerSetup/SomeServiceClass.ts:SomeServiceClass#21497",
	props : [{n : "propertyName", t : (0, tst_reflect_1.getType)({n : "string", k : 2}), am : 2, acs : 0, ro : false, o : false}],
	meths : [{
		n      : "getMessage",
		params : [],
		rt     : (0, tst_reflect_1.getType)({n : "string", k : 2}),
		tp     : [],
		o      : false,
		am     : 2,
	}, {n : "randomMethod", params : [], rt : (0, tst_reflect_1.getType)({n : "void", k : 2}), tp : [], o : false, am : 2}],
	ctors : [{params : []}],
	ctor  : () => SomeServiceClass_1.SomeServiceClass,
	iface : (0, tst_reflect_1.getType)(21493),
}, 21497);
const someServiceClass = (0, tst_reflect_1.getType)(21497);
const ctor             = someServiceClass.ctor;
const t                = Reflect.construct(ctor, []);
//# sourceMappingURL=Test.js.map

Essentially the import for “SomeServiceClass” is removed from the file

So when we call Reflect.construct(ctor, []) it cannot reference the actual module and this error is thrown: ReferenceError: SomeServiceClass_1 is not defined

When I use the metadata file, it just becomes null instead 🤔

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
iDevelopThingscommented, Jan 28, 2022

Ahh… its not far off working, just a couple of things to work out 😄

image

0reactions
Hookynscommented, Feb 5, 2022

Merged in #18

Read more comments on GitHub >

github_iconTop Results From Across the Web

Constructor on type not found - Stack Overflow
Exception Message: Constructor on type StateLog not found . I have the following code that does not work for only one class: List<T>...
Read more >
Each parameter in constructor 'Void .ctor(System.Guid, System ...
Hi, I'm facing an issue when using System.Text. ... String)' on type 'xxxxxxx' must bind to an object property or field on deserialization....
Read more >
Constructors, C++ FAQ
This question covers the C++11 feature of constructors that call same-type constructors. Nope. Let's work an example. Suppose you want your constructor Foo:: ......
Read more >
Constructors in C++ - GeeksforGeeks
Constructor in C++ is a special method that is invoked automatically at the time of object creation. It is used to initialize the...
Read more >
Writing a constructor in TypeScript - LogRocket Blog
With a constructor on the interface, you can specify that all of your types must have certain methods/properties (normal interface compliance) ...
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