In a .d.ts
file, how do I define an object as having string keys and T
values?
e.g.
declare var Game: {
creeps: Object<string, Creep>; // not sure what syntax to use here
};
declare class Creep {
// definition...
}
Game.creeps
is an object
, but I don't know what properties/keys it will have (they're defined at run time -- I'm using it like a dictionary), however, I do know that all its values will be Creep
s.
My IDE says "Object is not generic" so I guess that syntax isn't quite right.
Use an index signature:
declare var Game: {
creeps: {[key:string]: Creep}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With