fix(openapi-react-query): reject undeclared query and path parameters - #2865
Open
isaacriehm wants to merge 1 commit into
Open
fix(openapi-react-query): reject undeclared query and path parameters#2865isaacriehm wants to merge 1 commit into
isaacriehm wants to merge 1 commit into
Conversation
Init was inferred from the init argument, so the init parameter type was derived from the argument itself and no property could be excess. The operation's shape only participated as a constraint, which is ordinary assignability. Contextually type init by the operation's own init instead. parseAs is the only part of init the response type reads, so it is inferred on its own type parameter rather than by inferring the whole init.
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: 97ec99f 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 |
1 task
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.
Changes
Fixes #2864.
An undeclared query or path parameter type-checked and was sent, as long as the object also held
one declared parameter.
Initis inferred from theinitargument, so the parameter type isderived from the argument itself and nothing can be excess against it.
The init argument is now contextually typed by the operation's own init
(
MaybeOptionalInit<Paths[Path], Method>) instead of by the inferredInit, which makes theundeclared key ordinary excess-property checking:
parseAsis the only part of init the response type depends on (FetchResponsereads it throughParseAsResponse), so it is now inferred on its own type parameter rather than by inferring thewhole init.
ParseAsOptdefaults tonever, whichParseAsInitmaps tounknownso theno-
parseAscase still resolves to the JSON response. It is declared last because a defaultedtype parameter cannot precede non-defaulted ones.
Initis left in place onUseMutationMethod, where it is still the inferred mutate variabletype. The four query-side signatures no longer need it, so
RequiredKeysOfnow reads thedeclared init directly, which is the same value it resolved to before.
Runtime is untouched: rebuilding released 0.5.4 with this change emits
index.mjsandindex.cjsbyte-identical to the published files.How to Review
pnpm run lint:tsis the real gate. The@ts-expect-errorassertions are the test.queryOptions > has correct parameter types(undeclared query param,undeclared path param). Reverting
src/index.tsturns both intoTS2578: Unused '@ts-expect-error' directive, so they do test this change.infers the response type from parseAstest assertsparseAs: "blob"still yieldsBloband the default still yields
string[]. That case was uncovered, and it is the one that failsunder the obvious alternative fix:
NoInferon the init parameter passes the entire existingsuite while silently widening every
parseAsresponse back to the default. The sameNoInferchange in
openapi-fetch'sInitParamfails its owntest/common/response.test.tson this.pnpm run test:js38 passed,pnpm run lint:jsclean,pnpm run buildsucceeds.useQuery/queryOptionscallsites): one real 400-producing bug found, no legitimate call shape regressed.
Behaviour change worth a changelog note: code currently passing undeclared parameters stops
compiling. Extra top-level init keys stay legal, since
InitWithUnknownsis unchanged, so this doesnot address #2642.
Checklist
docs/updated (if necessary): no documented behaviour changespnpm run update:examplesrun (only applicable for openapi-typescript)Changeset:
.changeset/exact-query-params.md,openapi-react-query: patch.