I've started to learn how to implement TypeScript decorator in my application.
So I started with setTimeout
. It's an method decorator which executes method after some time.
For example:
@Decorators.timeout()
public someMethod () {}
Here is my implementation:
export class Decorators {
public static timeout (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): any {
let originalMethod = descriptor.value;
let decArguments = arguments;
descriptor.value = function Timeout () {
setTimeout(() => {
originalMethod.apply(this, decArguments);
}, 2000);
};
return descriptor;
}
}
This is error I'm getting:
Supplied parameters do not match any signature of call target
What could be the problem?
I've started to learn how to implement TypeScript decorator in my application.
So I started with setTimeout
. It's an method decorator which executes method after some time.
For example:
@Decorators.timeout()
public someMethod () {}
Here is my implementation:
export class Decorators {
public static timeout (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>): any {
let originalMethod = descriptor.value;
let decArguments = arguments;
descriptor.value = function Timeout () {
setTimeout(() => {
originalMethod.apply(this, decArguments);
}, 2000);
};
return descriptor;
}
}
This is error I'm getting:
Supplied parameters do not match any signature of call target
What could be the problem?
Share Improve this question edited Nov 7, 2017 at 11:30 Stefan Svrkota 50.7k10 gold badges99 silver badges88 bronze badges asked Nov 6, 2017 at 10:11 Никита УрсуНикита Урсу 611 gold badge1 silver badge5 bronze badges2 Answers
Reset to default 8You are missing args
in your Timeout()
function and you should pass those args
to original method:
descriptor.value = function Timeout (...args) {
setTimeout(() => {
originalMethod.apply(this, args);
}, 2000);
};
You should then delete this line because it's not doing anything:
let decArguments = arguments;
You can take a look at the delay decorator in the utils-decorators lib: Here is a link to the documentation: https://github./vlio20/utils-decorators#delay-method
and here to the implementation: https://github./vlio20/utils-decorators/blob/master/src/delay/delay.ts
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745647707a4638070.html
评论列表(0条)