Repository: pmndrs/zustand
File: src/index.ts (TypeScript)

Code before:
      // Destructure in the listener to get current values. We rely on this
      // because options is mutated in useStore.
      const { selector = getState, equalityFn = Object.is } = options
      // Selector or equality function could throw but we don't want to stop
      // the listener from being called.
      // https://github.com/react-spring/zustand/pull/37
      try {
        const newStateSlice = selector(state)
        if (!equalityFn(options.currentSlice as StateSlice, newStateSlice)) {
          listener((options.currentSlice = newStateSlice))
        }
      } catch (error) {
        options.subscribeError = error
        listener()
      }
    }
    listeners.add(listenerFn)
    return () => void listeners.delete(listenerFn)
  }

  const destroy: Destroy = () => listeners.clear()

  const useStore = <StateSlice>(
    selector: StateSelector<TState, StateSlice> = getState,
    equalityFn: EqualityChecker<StateSlice> = Object.is
  ): ReturnState<TState, StateSlice> => {
    if (Array.isArray(equalityFn)) {
      equalityFn = Object.is
      console.warn(
        'Zustand: the 2nd arg for dependencies was deprecated in 1.0. Please remove it! See: https://github.com/react-spring/zustand#selecting-multiple-state-slices'
      )
    }

    const isInitial = useRef(true)
    const options = useRef(
      // isInitial prevents the selector from being called every render.
      isInitial.current && {
        selector,
        equalityFn,
        currentSlice: ((isInitial.current = false), selector(state)),
      }
    ).current as SubscribeOptions<TState, StateSlice>

    // Update state slice if selector has changed or subscriber errored.
    if (selector !== options.selector || options.subscribeError) {
      const newStateSlice = selector(state)
      if (!equalityFn(options.currentSlice as StateSlice, newStateSlice)) {
        options.currentSlice = newStateSlice
      }
    }


Review comment (suggestion):
The `: {TYPE}` can be removed to let TypeScript infer the return type.

Code after:
      // because options is mutated in useStore.
      const { selector = getState, equalityFn = Object.is } = options
      // Selector or equality function could throw but we don't want to stop
      // the listener from being called.
      // https://github.com/react-spring/zustand/pull/37
      try {
        const newStateSlice = selector(state)
        if (!equalityFn(options.currentSlice as StateSlice, newStateSlice)) {
          listener((options.currentSlice = newStateSlice))
        }
      } catch (error) {
        options.subscribeError = error
        listener()
      }
    }
    listeners.add(listenerFn)
    return () => void listeners.delete(listenerFn)
  }

  const destroy: Destroy = () => listeners.clear()

  const useStore = <StateSlice>(
    selector: StateSelector<TState, StateSlice> = getState,
    equalityFn: EqualityChecker<StateSlice> = Object.is
  ) => {
    if (Array.isArray(equalityFn)) {
      equalityFn = Object.is
      console.warn(
        'Zustand: the 2nd arg for dependencies was deprecated in 1.0. Please remove it! See: https://github.com/react-spring/zustand#selecting-multiple-state-slices'
      )
    }

    const isInitial = useRef(true)
    const options = useRef(
      // isInitial prevents the selector from being called every render.
      isInitial.current && {
        selector,
        equalityFn,
        currentSlice: ((isInitial.current = false), selector(state)),
      }
    ).current as SubscribeOptions<TState, StateSlice>

    // Update state slice if selector has changed or subscriber errored.
    if (selector !== options.selector || options.subscribeError) {
      const newStateSlice = selector(state)
      if (!equalityFn(options.currentSlice as StateSlice, newStateSlice)) {
        options.currentSlice = newStateSlice
      }
    }

    useIsoLayoutEffect(() => {