I am trying to get typescript type-queries to work in classes.
Normally type-queries work like this:
const user = { name: "Patrick", age: 17 };
let typeofUser: typeof user;
In the example above the "typeofUser" would have the the type:
{ name: string, age: number }
So far so good. But I'm trying to get type-queries to work with classes. For example:
class App {
states = {
menu: {
login() {
console.log("Menu.login");
}
},
game: {
update() {
console.log("Game.update");
}
}
};
constructor() {
// FAILS => Cannot find name "states"
const typeofStates: typeof states = {};
// FAILS => Cannot find name "states"
const keyofStates: keyof states = "game";
}
}
My question is: How can I access class members for type-queries, with eighter the "typeof" or "keyof" operator?
typeof App.prototype.statesandkeyof typeof App.prototype.states.App['states']andkeyof App['states']