To type a dictionary of arrays, you can use an indexed type query in TypeScript. Here is an example:
177 chars11 lines
In this example, the DictionaryOfArrays
type alias takes a generic type parameter T
. The type alias defines an object type with string keys, and each key maps to an array of type T
.
You can then use this type alias to declare a variable like myDict
that is a dictionary of number arrays. In this example, we've assigned some example values to the dictionary just for demonstration purposes.
Note that TypeScript also includes a built-in Record
type for defining dictionaries. You could use Record<string, T[]>
to achieve the same result as the DictionaryOfArrays
type alias.
gistlibby LogSnag