Rematch utility types
Since version 2 of Rematch, which was released on February 1, 2020, it is fully compatible out of the box with TypeScript. There are some key concepts that are important to understand in terms of how Rematch makes it possible to type every corner of our state.
We will start with the first one we should create when creating a Rematch application with TypeScript.
RootModel
RootModel
, or whatever you want to call this interface, is the main interface of our store. It's a TypeScript interface that stores all of our model's types:
import { Models } from '@rematch/core' import { count } from './models/count' export interface RootModel extends Models<RootModel> { count: typeof count } export const models: RootModel = { count }
We need to create a circular cycle where RootModel
is injected as a generic type into the Models
type because Rematch architecture and how it's designed makes...