fix(rest): type update.buildHeaders params with UpdateParams<any>#7456
fix(rest): type update.buildHeaders params with UpdateParams<any>#7456yashs33244 wants to merge 1 commit into
Conversation
The update.buildHeaders option in createDataProvider was typed as
BuildHeaders<UpdateParams>, which resolves variables to the default {}
instead of any. Every other update option (getEndpoint, buildQueryParams,
buildBodyParams, mapResponse, transformError) and the default implementation
use UpdateParams<any>, so a custom update.buildHeaders callback could not read
fields off params.variables without a type error. Align the type with the rest
of the update options and add a test that derives a header from params.variables.
🦋 Changeset detectedLatest commit: 00e70e4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Hi @BatuhanW, would you mind taking a look when you have a moment? This types I've got two other small fixes open in the same spirit if they're useful: #7455 (typo fixes in user-facing error messages) and #7457 (reject non-finite values in |
Summary
In
@refinedev/rest,UpdateParams<TVariables = {}>defaults to{}. Theupdate.buildHeadersoption was typedBuildHeaders<UpdateParams>(no type arg), so a consumer's customupdate.buildHeaderssawparams.variablesas{}and couldn't read any field off it without a TypeScript error.This was the single outlier: all 9 other
buildHeadersdeclarations, every otherupdateoption, and the default implementation use<any>. Siblingupdate.buildBodyParams/transformErroralready worked; onlyupdate.buildHeaderswas affected.Changes
packages/rest/src/types.ts:BuildHeaders<UpdateParams>→BuildHeaders<UpdateParams<any>>custom buildHeaderstest inupdate.spec.ts(readsparams.variables.foo, asserts the derived header) + apatchchangesetTesting
@refinedev/coretypes: reverting the line makesupdate.spec.tsfail withTS2339: Property 'foo' does not exist on type '{}'biome ciclean; full@refinedev/restvitest suite 90 tests pass