I have a situation where I am trying to optimize my code by defining a derivative type inside a generic class in TypeScript. The goal is to avoid writing the derivative type every time, but I keep running into an error.
Here is the current version that is working:
class MyClass<T> {
t: T
doSomeThing(f: (t: T) => void) {}
doAnotherThing(g: (t: T) => void) {}
}
However, the version I want to implement, which is not working as intended, looks like this:
class MyClass<T> {
static type FT = (t: T) => void
// throws error: I can't define type or interface inside class
t: T
doSomeThing(f: FT) {}
doAnotherThing(g: FT) {}
}
If you have any insights on the right approach and solution for this problem, I would greatly appreciate it. Thank you.