I am seeking to extract the response type of a method that I apply a custom decorator to (specifically an old-style TypeScript experimental decorator, not the newer JS decorators). This is necessary in order to utilize the property names within the response as parameters within the decorator itself.
The code snippet below demonstrates my current approach:
type TaskProps<T, M> = {
next: keyof T;
param: ReturnType<M> extends {} ? keyof ReturnType<M> : string;
};
function Task<T, K extends keyof T>(props: TaskProps<T, T[K]>) {
return function (target: T, propertyKey: K, descriptor: PropertyDescriptor) {
};
}
class ExampleClass {
@Task({
next: "bye",
param: "name",
})
hello() {
return {
name: "example",
age: 11
};
}
bye() {}
}
Upon attempting to assign the type M to the ReturnType, an error message stating:
Type 'M' does not satisfy the constraint '(...args: any) => any'.