0

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?

0

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.