TypeScript - can a generic constraint provide “allowed” types?
Given the following code... type Indexable<TKey, TValue> = { [index: TKey]: TValue } This produces the following error: An index signature parameter type must be 'string' or 'number'. Is there a way to constrain TKey to be 'string' or 'number'? As @TitianCernicova-Dragomir indicates, you can't use TKey as the type in an index signature, even if it is equivalent to string or number . If you know that TKey is exactly string or number , you can just use it directly and not specify TKey in your type: type StringIndexable<TValue> = { [index: string]: TValue } type NumberIndexable<TValue> = { [index