I am learning TypeScript and I would like to define an interface for function decorators : function that accept a function and return a function.
Here is a snippet that gives the flavor of what I am trying to define:
interface IDecoratorFn {
(fn:function):function
}
Can this interface be specified in TypeScript ?
You're almost there, just need to use Function
instead of function
:
interface IDecoratorFn {
(fn: Function): Function;
}
You can also define a type alias:
type IDecoratorFn = (fn: Function) => Function;
typescript has built-in types.
In your case, use MethodDecorator as type directly
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.