Description
I found a break in zustand from looking at the logs of a failed NewErrors run. It might be more correct, but figured it was worth noting.
export type Store<T extends object> = {
setState: (x: T) => void
getState: () => T;
}
type ExtractState<S> = S extends { getState: () => infer T } ? T : never
type Extractable<S extends Store<object>> = {
getServerState?: () => ExtractState<S>
}
export function f<TState extends object>(api: Extractable<Store<TState>>) {
// ~~~~~~~~~~~~~
// Type 'Store<TState>' does not satisfy the constraint 'Store<object>'.
// Types of property 'setState' are incompatible.
// Type '(x: TState) => void' is not assignable to type '(x: object) => void'.
// Types of parameters 'x' and 'x' are incompatible.
// Type 'object' is not assignable to type 'TState'.
// 'object' is assignable to the constraint of type 'TState', but 'TState' could be instantiated with a different subtype of constraint 'object'.
}
https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/src/react.ts#L30
export function useStore<TState extends State, StateSlice>(
api: WithReact<StoreApi<TState>>,
// ~~~~~~~~~~~~~~~~
// error TS2344: Type 'StoreApi<TState>' does not satisfy the constraint 'StoreApi<object>'.
There's a few of these.
New errors for non-composite project https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/tsconfig.json
-
TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/src/react.ts#L30
error TS2344: Type 'StoreApi<TState>' does not satisfy the constraint 'StoreApi<object>'.
-
TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/src/react.ts#L56
error TS2344: Type 'Mutate<StoreApi<T>, Mos>' does not satisfy the constraint 'WithReact<StoreApi<object>>'.
-
TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/src/react.ts#L59
error TS2344: Type 'Mutate<StoreApi<T>, Mos>' does not satisfy the constraint 'WithReact<StoreApi<object>>'.
-
TS2345 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/src/react.ts#L68
error TS2345: Argument of type 'StoreApi<T>' is not assignable to parameter of type 'WithReact<StoreApi<object>>'.
-
error TS2344: Type 'StoreApi<CounterState>' does not satisfy the constraint 'StoreApi<object>'.
-
error TS2344: Type 'StoreApi<CounterState>' does not satisfy the constraint 'StoreApi<object>'.
-
error TS2344: Type 'StoreApi<CounterState>' does not satisfy the constraint 'StoreApi<object>'.
-
error TS2344: Type 'StoreApi<CounterState>' does not satisfy the constraint 'StoreApi<object>'.
-
error TS2322: Type 'StoreApi<Omit<{ count: number; }, never>>' is not assignable to type 'StoreApi<object>'.
-
error TS2344: Type 'StoreApi<ExampleState>' does not satisfy the constraint 'WithReact<StoreApi<object>>'.
Originally posted by @DanielRosenwasser in #49488 (comment)