0

I've recently been doing more exploration in advance TS types and was going through react type declarations when I came Accross this

    type RefCallback<T> = { bivarianceHack(instance: T | null): void }["bivarianceHack"];

can someone explain what ["bivarianceHack"] means and what it does? Not the string itself, but wondering why an array is declared after like type T = {}[] <-- []

Rogelio
  • 953
  • 2
  • 10
  • 19
  • 1
    `[]` is not array in `type T = {}[]`. It's *index operator*. Like you can get property from an object by `{name: "Jack"}["name"]`, You can get the subtype from an Object Type by `type Name = {name: string}["name"]`, Which means `type Name = string`. – BigLiao Sep 02 '22 at 02:07

0 Answers0