When defining a method type signature, it is possible to use keyof this
to restrict an argument to the string name of a valid key of the class. However, using this approach does not work when the method accepts options-style arguments instead of positional ones. For example:
class Foo {
// Allowed
m1(a: string, b: keyof this) {
...
}
// Error: A 'this' type is available only in a non-static member of a class or interface
m2(options: {a: string, b: keyof this}) {
...
}
}
Is there any workaround for this limitation? Thank you.