DEV Community

loading...

Discussion on: Indexing objects in TypeScript

Collapse
newswim profile image
Dan Minshew • Edited

Nice! I ended up opting for the union type, just because any gives me anxiety . .

function hasKey<O>(obj: O, key: string | number | symbol): key is keyof O {
  return key in obj
}
Thread Thread
mapleleaf profile image
MapleLeaf Author

👍 Might even be more readable that way.