Skip to content

`createApi` better types

Choose a tag to compare

@neurosnap neurosnap released this 10 Feb 04:56
· 22 commits to main since this release
f4d3181
feat(createApi): better types

`createApi().[method]` has better type support for inferring `ctx`
properties.

```ts
import { createApi } from 'saga-query';

interface Props { id: string }
interface Success { result: string }
interface Err { message: string }

const api = createApi();

const fetchUser = api.get<Props, Success, Err>(
    '/users/:id',
    function*(ctx, next) {
        // will be set to `Props`
        ctx.payload;

        yield next();

        if (ctx.json.ok) {
            // will be set to `Success`
            ctx.json.data;
        } else {
            // will be set to `Err`
            ctx.json.data;
        }
    },
);

dispatch(fetchUser({ id: '1' }));
```