Looking for a problem I have, I found statements that the order of the class declarations does not matter in Typescript , and that 'forward declarations' are not necessary.
In the project that I am considering right now, this statement does not seem to be delayed. I confused the problem with a simple reproducible example where, although the compiler does not complain, we fail at runtime:
$ cat bug.ts
class A extends B {
constructor(public id:number) {
super(id);
console.log("A():" + id);
}
}
class B {
constructor(public id:number) {
console.log("B():" + id);
}
}
var a = new A(12);
$ tsc bug.ts
$ node bug.js
/home/ttsiod/work/a/bug.js:4
__.prototype = b.prototype;
^
TypeError: Cannot read property 'prototype' of undefined
at __extends (/home/ttsiod/work/a/bug.js:4:21)
at /home/ttsiod/work/a/bug.js:8:5
at Object.<anonymous> (/home/ttsiod/work/a/bug.js:15:3)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
Either I’m missing a keyword that I don’t know about, or the statement “the order of the announcement does not matter” is not as general as one might think.
source
share