You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a Typescript project which generates a single bundled .js library for use in client-side webapps. I am using namespaces and /// references. I would like to get design/build-time errors when one file in the library depends on another file and there is no /// reference present; otherwise, it won’t be discovered until runtime. The compiler catches the missing reference in a number of cases, but not if a static variable is declared and assigned in a class's definition.
e.g.: with the following, I get a nice compile-time error:
// AClass.ts
namespace test {
export class AClass extends ZClass {
constructor() {
super();
}
}
}
...
// ZClass.ts
namespace test {
export class ZClass {
constructor() {
}
}
}
TSC complains that error TS2690: A class must be declared after its base class as expected, and adding /// <reference path=’zclass.ts’ fixes it, again as expected.
The problem is when you instantiate a static variable, it doesn’t seem to get caught at build time. e.g., change the above code as follows:
// AClass.ts
namespace test {
export class AClass {
static z = new ZClass();
constructor() {
}
}
}
...
// ZClass.ts
namespace test {
export class ZClass {
constructor() {
}
}
}
When you compile now, no build errors are emitted; but when you run you get "test.AClass is not a constructor" because ZClass isn’t defined at this point in the bundled .js file; that definition occurs after AClass. If you switch the object names, then it works. Or, if you add /// <reference path="ZClass.ts"/> to AClass.ts, it works.
Should TSC output a build error in this scenario? My concern is that it's easy to miss adding one of those references.
The text was updated successfully, but these errors were encountered:
I have a Typescript project which generates a single bundled .js library for use in client-side webapps. I am using namespaces and /// references. I would like to get design/build-time errors when one file in the library depends on another file and there is no /// reference present; otherwise, it won’t be discovered until runtime. The compiler catches the missing reference in a number of cases, but not if a static variable is declared and assigned in a class's definition.
e.g.: with the following, I get a nice compile-time error:
TSC complains that
error TS2690: A class must be declared after its base class
as expected, and adding/// <reference path=’zclass.ts’
fixes it, again as expected.The problem is when you instantiate a static variable, it doesn’t seem to get caught at build time. e.g., change the above code as follows:
When you compile now, no build errors are emitted; but when you run you get
"test.AClass is not a constructor"
because ZClass isn’t defined at this point in the bundled .js file; that definition occurs after AClass. If you switch the object names, then it works. Or, if you add/// <reference path="ZClass.ts"/>
to AClass.ts, it works.Should TSC output a build error in this scenario? My concern is that it's easy to miss adding one of those references.
The text was updated successfully, but these errors were encountered: