Skip to content

Return type of transformResponse on enhanceEndpoints can not differ from original definition in createApi #1441

@bkempe

Description

@bkempe

Currently, the return type of transformResponse on enhanceEndpoints has to match the original return type from createApi.
This diminishes the value and ability of enhanceEndpoints:
Often, it is preferred to have client code use different shapes than the ones exposed by an API and transformResponse is the mechanism to do so.
However, once RTK codegen is used, transformResponse should be defined on enhanceEndpoints and not on the (generated) createApi.

Example

Using the enhancedEndpoints example from the docs, this usage of transformResponse currently fails to compile:

getPetById: {
    providesTags: (result, error, arg) => [{type: 'Pet', id: arg.petId}],
    transformResponse: ({id, name, category, photoUrls, tags, status}) => ({id, name}),
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions