I followed some tutorials like http://www.html5rocks.com/en/tutorials/frameworks/angular-websockets/ to implement socket.io in my node.js server and angular.js client, everything works fine.
However, client side, Typescript display following compilation error:
TS2496: The 'arguments' object cannot be referenced in an arrow function in ES3 and ES5. Consider using a standard function expression.
Regarding following service codes:
on(eventName:string, callback) {
this.socket.on(eventName, () => {
var args = arguments; // <-- here the compilation error
this.$rootScope.$apply(() => {
callback.apply(this.socket, args);
});
});
}
emit(eventName:string, data, callback?) {
this.socket.emit(eventName, data, () => {
var args = arguments; // <-- here the compilation error
this.$rootScope.$apply(() => {
if (callback) {
callback.apply(this.socket, args);
}
});
});
}
I tried different solutions, like the one described in the first post of https://github.com/Microsoft/TypeScript/issues/1609, which fix the compilation but break the socket.io "on" functionality (the json objects aren't interpreted anymore).
Any idea how to fix or ignore this typescript compilation error?
Another possibility is to use a rest parameter instead of arguments
:
on(eventName:string, callback) {
this.socket.on(eventName, (...args) => {
this.$rootScope.$apply(() => {
callback.apply(this.socket, args);
});
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With