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
{{ message }}
Repository navigation
Runtime error when mixing into Object with es5 target #18564
typeConstructor<T={}>=new(...args: any[])=>T;functionMixin<TextendsConstructor>(Base: T){returnclassextendsBase{NonArrowFunction(){console.log("Non Arrow Function");}ArrowFunction=()=>{console.log("Arrow Function");}}}classAextendsMixin(Object){constructor(){super()// No runtime errorsthis.ArrowFunction();// Runtime error in es5 exportthis.NonArrowFunction();}}newA();
Expected behavior:
No runtime error when compiled with --target es5 and run with latest node version.
Actual behavior:
TypeError: _this.NonArrowFunction is not a function
at new A (C:\Users\Daniel\Desktop\mixines5.js:31:15)
at Object.<anonymous> (C:\Users\Daniel\Desktop\mixines5.js:36:1)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
The runtime error does not happen when mixing into an empty class as opposed to Object.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
DanielRosenwasser commentedon Sep 19, 2017
Unfortunately this is a duplicate of #10762 and ES5-compliant emit can't properly model subclassing certain built-ins.
Check out the FAQ here: https://github.com/Microsoft/TypeScript/wiki/FAQ#why-doesnt-extending-built-ins-like-error-array-and-map-work
If it's available to you, you can call
Object.setPrototypeOfat the end of your constructor.JustASquid commentedon Sep 19, 2017
Daniel Rosenwasser (@DanielRosenwasser) Thank you! What would you say would be the best way to describe mixing into an 'empty class' like this? Using
is a bit verbose.
aluanhaddad commentedon Sep 19, 2017
Daniel West (@JustASquid) what about
or you can adjust your mixin function, making the argument optional.
mhegazy commentedon Oct 3, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.