-
Notifications
You must be signed in to change notification settings - Fork 21
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
Object.setPrototypeOf() method is missing / not transpiled correctly #264
Comments
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
would be nice if somebody could look at this |
Hi @pe1pip , could you share what issue or error you are encountering in vRO with this setup? It should be possible to extend the error object without an issue. Do you need to explicitly call the "Object.setPrototypeOf" function?
|
I am not sure in this case of inheritance whether you will really need the Object.setPrototypeOf() call but we should be able to extend and add this function. |
the problem arises if you want additional properties in the Error object, in this case the export class NsxtError extends Error {
public readonly cause: ErrorCause
constructor (p: string, m: string, cause: ErrorCause) {
super(`${p}${m}`)
Object.setPrototypeOf(this, new.target.prototype) // restore this object
this.cause = cause
}
} |
Interesting..in theory "extends" keyword should be enough. However, in my tests I found that without Object.setPrototypeOf() everything seems to work for the error but if you log err.constructor.name it logs "Error". But if you add the setPrototypeOf() call as in your sample err.constructor.name will log NsxtError. I think I managed to get it running at least with a simple test. If everything is ok I will open a PR tomorrow but it would be great to double check on your side as well |
This is a well documented 'feature' of typescript, see for example: https://stackoverflow.com/questions/41102060/typescript-extending-error-class and https://github.com/microsoft/TypeScript-wiki/blob/7adbad944469a2943c1ba2032a1fb1735b89a8f3/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work (I had to go a bit back in history of that file). So, until Mozilla Rhino/Orchestrator gets 'https://mozilla.github.io/rhino/compat/engines.html#ES2015-functions-arrow-functions-lexical--new-target--binding' fixed we have this issue. |
@pe1pip whenever you have time could you check and possibly test on your side as well: https://github.com/vmware/build-tools-for-vmware-aria/pull/277/files |
Hi @VenelinBakalov , I have a build error in vropkg, this is probably something in my environment, but I have no time to investigate. The PR looks quite ok, so I have little doubt that it works. |
Got it, thanks for pointing out this issue and adding the related documentation links, that was really helpful! |
Regarding #264 Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
Description
I want to extend the Error class. Apparently the transpilation of the code is incorrect:
Is transpiled to:
and it should be:
Alternatives
don't know.
Additional Context
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget
The text was updated successfully, but these errors were encountered: