Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • You want a mapped type instead of an index signature... it looks like {[P in K]: V} instead of {[k: K]: V}. This is equivalent to Record<K, V>. See the answer to the linked question for more information. Commented Nov 27, 2021 at 20:59
  • That won't work either because P in K will treat K as a union of string values. I'm looking to get the type of k not the value. Something like [k: string]: V] that will work but if I replace string with K`. It won't be happy. Commented Nov 27, 2021 at 21:20
  • Well I’ve reopened the question but I don’t understand how Record<K, V> doesn’t work for you. You say “it won’t work”… have you tried it? Commented Nov 27, 2021 at 21:23
  • Make sure to update the error to "Type 'K' is not assignable to type 'string | number | symbol'" instead of "An index signature parameter type must be either 'string' or 'number'". Commented Nov 28, 2021 at 3:20