admin管理员组文章数量:1026445
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
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
本文标签: javascriptTypeScript decorator for setTimeout() functionStack Overflow
版权声明:本文标题:javascript - TypeScript decorator for setTimeout() function - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745647705a2161124.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论