yarn @reduxjs/toolkit 1.3.0-alpha.4
v1.3.0-alpha.4

latest releases: 2.2.3, 2.2.2, 2.2.1...
4 years ago

This alpha release rearranges the TS generic types of createAsyncThunk to fix broken usage.

Changes

createAsyncThunk Types

createAsyncThunk gives you access to getState in the thunkAPI object argument. However, we hadn't tried to exercise that yet in our tests, and it turns out there was no valid way to specify the correct type of the state returned by getState.

We've rearranged the generic types and tweaked the defaults. You should now be able to use it without specifying any generics for the most common case (returning a value, with a potential argument for the payload callback), and specify three types if you need to declare what the state type is:

// basic usage:
const thunk1 = createAsyncThunk("a", async (arg: string) => {
    return 42
})
// infers: return = Promise<number>, arg = string

// specify state type for getState usage
const thunk2 = createAsyncThunk<Promise<number>, string, RootState>(
    "a",
    async (arg: string, {getState}) => {
        const state = getState();
        return 42;
    }
)
// declared: return = Promise<number>, arg = string, state: RootState

We have some ideas for additional potential improvements to these types that may make usage simpler, so please keep an eye out for further alpha releases.

Documentation

A first draft of API documentation for createAsyncThunk is now available:

createAsyncThunk draft API reference

Changes

v1.3.0-alpha.3...v1.3.0-alpha.4

See PR #352: Port ngrx/entity and add createAsyncThunk for the complete alpha changes.

Don't miss a new toolkit release

NewReleases is sending notifications on new releases.