I'm trying to write a d.ts file for an API which has a collection object representing an ordered collection of key-value pairs. The keys and values are all strings. Thus, the behavior is:
thing["foo"]returns the string value of the pair where key is "foo"thing[1]returns the string value of the second pair in the ordered collectionthing.lengthreturns the count of key-value pairs as a number
I tried the following, but it produced the error "An index signature parameter must be type 'string' or 'number':
declare class FrobCollection {
[index: string|number] : string;
}
Is there a way to model the behavior of this object correctly in TypeScript?
EDIT: I found a way to model the two indexers, but still can't get the length property to work.