fix: authorize undefined values in DataMatcher type#1723
Closed
jgiovaresco wants to merge 1 commit intonock:masterfrom
Closed
fix: authorize undefined values in DataMatcher type#1723jgiovaresco wants to merge 1 commit intonock:masterfrom
jgiovaresco wants to merge 1 commit intonock:masterfrom
Conversation
When the type used in `.query` defines optional keys using undefined, TypeScript was complaining :
```
Error:(59, 19) TS2345: Argument of type '{ a: string; b?: string | undefined; }' is not assignable to parameter of type 'string | boolean | DataMatcher | URLSearchParams | ((parsedObj: ParsedUrlQuery) => boolean)'.
Type '{ a: string; b?: string | undefined; }' is not assignable to type 'DataMatcher'.
Property 'b' is incompatible with index signature.
Type 'string | undefined' is not assignable to type 'string | number | boolean | RegExp | DataMatcher | (string | number | boolean | RegExp | DataMatcher | null)[] | null'.
Type 'undefined' is not assignable to type 'string | number | boolean | RegExp | DataMatcher | (string | number | boolean | RegExp | DataMatcher | null)[] | null'.
```
paulmelnikow
approved these changes
Sep 19, 2019
Member
|
Thanks for this @jgiovaresco, this is definitely a bug. I'd like to hold off on merging this PR while I continue testing my in-progress work. But I am going to borrow your test file changes to make sure this use case is covered. |
mastermatt
added a commit
to mastermatt/nock
that referenced
this pull request
Sep 19, 2019
Fixes: nock#1724 Closes: nock#1723 Updates the JSONish type using inspiration from the thread on adding a JSON type to TS. microsoft/TypeScript#1897 (comment) This change does a couple sublet things: - Adds `undefined` to scalar values allowed in arrays or as values in objects. This allows for interfaces with optional keys to be passed in. ref nock#1723 - Splits out top-level array and objects into their interfaces so they could be used directly. Allows enforcing non-arrays for `.query`. - `RequestBodyMatcher` now extends the array and map types instead of the raw `DataMatcher`. Allowing arrays fixes nock#1724. This also ensures that booleans, numbers, and `null` are not considered valid.
mastermatt
added a commit
that referenced
this pull request
Sep 20, 2019
* fix(types): data matcher for body and query. Fixes: #1724 Closes: #1723 Updates the JSONish type using inspiration from the thread on adding a JSON type to TS. microsoft/TypeScript#1897 (comment) This change does a couple sublet things: - Adds `undefined` to scalar values allowed in arrays or as values in objects. This allows for interfaces with optional keys to be passed in. ref #1723 - Splits out top-level array and objects into their interfaces so they could be used directly. Allows enforcing non-arrays for `.query`. - `RequestBodyMatcher` now extends the array and map types instead of the raw `DataMatcher`. Allowing arrays fixes #1724. This also ensures that booleans, numbers, and `null` are not considered valid.
Collaborator
|
🎉 This issue has been resolved in version 11.3.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
juninmd
pushed a commit
to juninmd/nock
that referenced
this pull request
Mar 21, 2026
* fix(types): data matcher for body and query. Fixes: nock#1724 Closes: nock#1723 Updates the JSONish type using inspiration from the thread on adding a JSON type to TS. microsoft/TypeScript#1897 (comment) This change does a couple sublet things: - Adds `undefined` to scalar values allowed in arrays or as values in objects. This allows for interfaces with optional keys to be passed in. ref nock#1723 - Splits out top-level array and objects into their interfaces so they could be used directly. Allows enforcing non-arrays for `.query`. - `RequestBodyMatcher` now extends the array and map types instead of the raw `DataMatcher`. Allowing arrays fixes nock#1724. This also ensures that booleans, numbers, and `null` are not considered valid.
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.
When the type used in
.querydefines optional keys using undefined, TypeScript was complaining :