Reputation: 17174
Having a *.d.ts file with the following definition:
class StateManager {
states(key:string): Phaser.State;
Can be accessed in two ways:
myStateManager.states[key]
myStateManager.states(key)
But only the first will actually work due to the JS definition of states:
this.states = {};
Is there a way to force the correct notation in typescript?
Upvotes: 0
Views: 2043
Reputation: 221352
It sounds like you want an index signature here instead?
class StateManager {
states: { [key: string]: Phaser.State };
}
var x = new StateManager();
var p: Phaser.State = x.states['hello']; // OK
var e = x.states('hello'); // Error
Upvotes: 1