Repository: TypeScript
Issue: Generics in conditionals have differing behavior in 4.8
Labels: Needs Investigation

I found a break in [zustand](https://github.com/pmndrs/zustand/) from looking at the logs of a failed NewErrors run. It might be more correct, but figured it was worth noting.

```ts
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

```ts
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>>'.
  ```
* TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/tests/context.test.tsx#L24

  ```
  error TS2344: Type 'StoreApi<CounterState>' does not satisfy the constraint 'StoreApi<object>'.
  ```
* TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/tests/context.test.tsx#L48

  ```
  error TS2344: Type 'StoreApi<CounterState>' does not satisfy the constraint 'StoreApi<object>'.
  ```
* TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/tests/context.test.tsx#L135

  ```
  error TS2344: Type 'StoreApi<CounterState>' does not satisfy the constraint 'StoreApi<object>'.
  ```
* TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/tests/context.test.tsx#L150

  ```
  error TS2344: Type 'StoreApi<CounterState>' does not satisfy the constraint 'StoreApi<object>'.
  ```
* TS2322 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/tests/middlewareTypes.test.tsx#L171

  ```
  error TS2322: Type 'StoreApi<Omit<{ count: number; }, never>>' is not assignable to type 'StoreApi<object>'.
  ```
* TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/tests/types.test.tsx#L86

  ```
  error TS2344: Type 'StoreApi<ExampleState>' does not satisfy the constraint 'WithReact<StoreApi<object>>'.
  ```


_Originally posted by @DanielRosenwasser in https://github.com/microsoft/TypeScript/issues/49488#issuecomment-1152817431_