You can achieve that just by using a
IDictionary<TValue> { [key: string]: TValue }
since numeric values will be automatically converted to string.
Here is an example of usage:
interface IDictionary<TValue> {
[id: string]: TValue;
}
class Test {
private dictionary: IDictionary<string>;
constructor() {
this.dictionary = {}
this.dictionary[9] = "numeric-index";
this.dictionary["10"] = "string-index"
console.log(this.dictionary["9"], this.dictionary[10]);
}
}
// result => "numeric-index string-index"
As you can see string and numeric indices are interchangeable.