Typescript
Overmind is written in Typescript and it is written with a focus on you dedicating as little time as possible to help Typescript understand what your app is all about. Typescript will spend a lot more time helping you. If you are not a Typescript developer Overmind is a really great project to start learning it as you will get the most out of the little typing you have to do.
Configuration
The only typing you need is the Context. This holds information about your state, actions and effects.
import { IContext } from 'overmind'
export const config = {}
export type Context = IContext<typeof config>You only have to set up these types once, where you bring your configuration together. That means if you use multiple namespaced configuration you still only create a single Context type.
State
The state you define in Overmind is just an object where you type that object.
type State = {
foo: string
bar: boolean
baz: string[]
user: User
}
export const state: State = {
foo: 'bar',
bar: true,
baz: [],
user: new User()
}When writing Typescript you should not use optional values for your state (?), or use undefined in a union type. In a serializable state store world null is the value indicating “there is no value”.
Derived
Note that the type argument you pass is the object the derived is attached to, so with nested derived:
To access the root state you can use your Context type:
Statemachine
Read the guide on Using state machines to understand how to type them.
Actions
You type your actions with the Context and an optional value. Any return type will be inferred.
Any of these actions could be defined as an async function or simply return a promise to be typed that way.
Effects
There are no Overmind specific types related to effects, you just type them in general.
Operators
Operators is like the action: it can take an optional value, but it always produces a promise output. By default the promised value of an operator is the same as the input.
When you create a pipe and inline other operators/actions their payloads are inferred. Only the first operator needs to type its payload so that when calling doThis you will have the correct typing for the initial payload.
Last updated