tst-reflect: Constructor(Type.ctor) type problems

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 🤔

About this issue

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

Commits related to this issue

Most upvoted comments

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

image