Skip to content

[REQ] let typescript-fetch initOverrides optional to be a function #11823

Closed
@loynoir

Description

@loynoir

Is your feature request related to a problem? Please describe.

#11744

Just like issue above, I also want to append header.

const init = {
    method: context.method,
    headers: headers,
    body,
    credentials: this.configuration.credentials,
    ...initOverrides
};

But {X, ...Y} is one level merging, not deep merging.

When initOverrides has key headers, prev key headers is gone.

So, current implement can't append header.

Describe the solution you'd like

Current signature

private createFetchParams(context: RequestOpts, initOverrides?: RequestInit)

Merging using {X, ...Y}

REQ

private createFetchParams(
    context: RequestOpts,
    initOverrides?: RequestInit | ((context: RequestOpts) => RequestInit)
)

Merging using {X, ...Y(X) }

Describe alternatives you've considered

Convert {X, ...Y} to some deep merging library fn(X, Y).

But consider openapi-generator target many language, I prefer former to decrease you guys maintenance burden.

Additional context

You guys are awesome. :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions