fix(rest): type update.buildHeaders params with UpdateParams<any>#7456
Open
yashs33244 wants to merge 1 commit into
Open
fix(rest): type update.buildHeaders params with UpdateParams<any>#7456yashs33244 wants to merge 1 commit into
yashs33244 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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