0

I have a case where I have a generic query that can return any type of collection and some subqueries that strictly expect return a Decks, Cards or Notes Collection, decks are indexed by name and return array of cards ids, cards by ids and return notes ids and notes by ids and return data.

export type Collection<K extends (number|string), V extends (number|string)> = { [key: K]: V[] }
export type DecksCollection = Collection<string, number>
export type CardsCollection = Collection<number, number>
export type NotesCollection = Collection<number, string>

It throw me An index signature parameter type must be either 'string' or 'number'.

I would like to write the first line correctly since I strictly expect strings or numbers, not both and K must be a number or string since for typescript it's an index.

Linda Paiste
  • 38,446
  • 6
  • 64
  • 102
y.petremann
  • 2,702
  • 1
  • 15
  • 19

0 Answers0