Is there any way to specify the type of object a keyof
is pointing to?
So that, for example:
type MyType = { a: string, b: number };
let myKey: keyof<string> MyType = "a"; // Valid
myKey = "b"; // Invalid
And then, when you use:
let myVar: MyType = { a: "Hello", b: 1 };
funcThatNeedsAString(MyType[myKey]);
it already knows that MyType[myKey]
is a string?