I'm writing my own decorators in typescript. Currently, my decorators look like this:
const Controller = (prefix = ''): ClassDecorator => (target: any): void => {
// My Logic
};
export default Controller;
My question is about the ClassDecorator argument. Currently, I'm using the any
type for the target
parameter but I need a specific type for this argument. So my question is how is this type named?
I googled for a while but found nothing about this.
You shouldn't need to explicitly state the return type of Controller because the compiler will infer it. as long as you type the arguments of your inner function ..
type MyType = { foo: number }
function f() {
console.log('f(): evaluated')
return function (target: MyType) {
console.log('f(): called' + target.foo)
}
}
``