1

Is something like this possible? It works for objects, but what about arrays?

const myArray = ["foo", "bar"]

function pick(what: keyof myArray) { // keyof is obviously wrong
}

pick("foo") // okay
pick("inexistent") // error, "inexistent" does not exist in myArray
kraftwer1
  • 5,253
  • 10
  • 36
  • 54

0 Answers0