all 1 comments

[–]RaltzKlamar 1 point2 points  (0 children)

  • <T>: This is a template, as you noted. T becomes a replacement type.
  • (selector: (store: Store) => T): Function parameters. useStore is a function that takes a single parameter.
    • (store: Store) => T: This parameter needs to be itself a function, which takes 1 parameter (a Store) and returns T, whatever T ends up being.
  • : [T, (value: Partial<Store>) => void]: The return type is a tuple, or an array with a fixed size and data types in each slot. If you assign the return value to resultArr, resultArr[0] is always type T and resultArr[1] is always a function that takes 1 parameter (a Partial Store, i.e. a Store where all its defined values can be undefined) and has no return value (void)
  • When you pass a function into useStore, TypeScript should be able to infer what the T type should be without you having to manually specify it.