a common use case for javascript objects is to use them as key-value storage... sort of like a dictionary:
var dictionary = {},
value;
dictionary['key a'] = 99;
dictionary['key b'] = 12;
value = dictionary['key a']; // 99
typescript intellisense goodness can be added by declaring an interface like this:
interface IIndexable<T> {
[s: string]: T;
}
and using the interface like this:
var dictionary: IIndexable<number> = {},
value: number;
dictionary['key a'] = 99;
dictionary['key b'] = 'test'; // compiler error: "cannot convert string to number"
var x = dictionary['key a']; // intellisense: "x" is treated like a number instead of "any".
here's my question: is it possible to declare a stand-alone version of this interface:
interface StackOverflow {
questions: IIndexable<number>;
}
ie without using IIndexable?
I tried doing something like this but it doesn't compile:
interface MyAttempt {
questions: [s: string]: number;
}