-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add explicit error to __extends when base class is undefined #5794
Comments
would #4343 be sufficient to address the underlying problem? |
It seems to me that PR only detects child before base in the same file? Does it handle, say, base class imported from another module that also has circular reference so base class is still undefined? |
Coincidentally the circular referenced superclass issue came up on stack overflow just the other day: http://stackoverflow.com/questions/33897273/typescript-and-systemjs-circle-dependency/33905499#33905499 |
you are correct, it does not handle circular references in modules, just in the same file, or if you are using --out. |
The other common case I see is that someone refactors into two script files and forgets to add a script tag for the file containing the base class. |
Out of curiosity, has the implementation of __extends changed recently? Ever since upgrading to 1.8, I seem to get these run time errors a lot more. Not sure if it is just a coincidence or what. |
@DavidKDeutsch If you're seeing it more with 1.8 then it might be 1.8 changed the ordering of your classes such that the base class is undefined (although it sounds unlikely). |
BTW, this can be especially confusing to developers when including other libraries that were also compiled with TypeScript, as the first file that defines __extends is where the error is thrown from. |
I am having the same issue even if the class is used after the other: BaseClass.ts:
ChildClass.ts:
Generates:
It seems that the order is correct, although it doesn't look like it is working as expected. But if I am merging two source files into one, then it is working well. BaseClassAndChileClass.ts:
|
We occasionally get people in the IRC channel asking about their transpiled JS failing with
TypeError: undefined is not an object
. It happens when accessingb.prototype
inside__extends
because the child class is before the base class, but they often think it's a bug in__extends
. Would it make sense to detect ifb
is undefined at the start of the function and throw an appropriately worded error? Eg:The text was updated successfully, but these errors were encountered: