Skip to content

Support undefined values for searchParams object - #729

Merged
sholladay merged 1 commit into
mainfrom
searchparams-undefined
Sep 3, 2025
Merged

Support undefined values for searchParams object#729
sholladay merged 1 commit into
mainfrom
searchparams-undefined

Conversation

@sindresorhus

Copy link
Copy Markdown
Owner

Fixes #293

Comment thread source/types/options.ts

// eslint-disable-next-line unicorn/prevent-abbreviations
export type SearchParamsOption = SearchParamsInit | Record<string, string | number | boolean> | Array<Array<string | number | boolean>>;
export type SearchParamsOption = SearchParamsInit | Record<string, string | number | boolean | undefined> | Array<Array<string | number | boolean>>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add null as an allowed type here?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's intentional. Developers can mistakenly expect null to behave like undefined then and have it serialized to "null" without it being intentional. I think it should be an intentional choice as the result may not be the expected behavior.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but I think as any will end up being relatively common and the JS/TS API will seem inconsistent.

Comment thread test/main.ts

const objectWithNull = {
cats: 'meow',
dogs: null as any,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see much value in requiring users to as any every null value. Seems like it would just be cumbersome.

@sholladay
sholladay merged commit a87d9e9 into main Sep 3, 2025
6 checks passed
@sholladay
sholladay deleted the searchparams-undefined branch September 3, 2025 02:44
@lespinozaguerrero6-png

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Support undefined or null value in searchParams?

3 participants