Skip to content

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

@raphaelpra

Description

@raphaelpra

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'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions