heroku / react-refetch

A simple, declarative, and composable way to fetch data for React components

Home Page:https://blog.heroku.com/react-refetch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Typescript] Type of "body" attribute must be string? and not object? on the Mapping interface

raphaelpra opened this issue · comments

As describe in documentation when implementing a POST and providing the body attribute you should do something like:

connect(() => ({
        login: (signInParams: ISignInParams) => ({
            loginResponse: {
                url: `${host}/session`,
                method: 'POST',
                body: JSON.stringify(signInParams)
            }
        })
    }))(newComponent)

However, this snippets doesn't compile with Typescript since the body is expected to be an object?.

Therefore it raise the following compilation error:

Type '(signInParams: ISignInParams) => { loginResponse: { url: string; method: string; body: string; }; }' is not assignable to type '(signIn: ISignInParams) => PropsMap'.
Type '{ loginResponse: { url: string; method: string; body: string; }; }' is not assignable to type 'PropsMap'.
Types of property 'loginResponse' are incompatible.
Type '{ url: string; method: string; body: string; }' is not assignable to type 'string | Mapping<SignInProps, {}> | undefined'.
Type '{ url: string; method: string; body: string; }' is not assignable to type 'Mapping<SignInProps, {}>'.
Types of property 'body' are incompatible.
Type 'string' is not assignable to type 'object | undefined'.