Skip to content

Default params always optional#699

Merged
stackoverfloweth merged 3 commits intomainfrom
default-params-always-optional
Feb 13, 2026
Merged

Default params always optional#699
stackoverfloweth merged 3 commits intomainfrom
default-params-always-optional

Conversation

@stackoverfloweth
Copy link
Copy Markdown
Contributor

@stackoverfloweth stackoverfloweth commented Feb 13, 2026

I've tripped over this multiple times and I'm not sure why we didn't just build it this way from the beginning.

Currently, a param with a default value is still considered required when stringifying

const url = createUrl({
  path: withParams('/[foo]', { foo: withDefault(Number, 42) }),
})

url.stringify()
//  ^ TS ERROR ❌

This PR updates that logic so that a parm with a default is always considered to be optional.

const url = createUrl({
  path: withParams('/[foo]', { foo: withDefault(Number, 42) }),
})

url.stringify()
//  ^ ok ✅

also works nicely for new query param syntax

const url = createUrl({
  query: {
    foo: withDefault(String, 'abc'),
  },
})

const response = url.stringify()
//  ^ ok ✅

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 13, 2026

Deploy Preview for kitbag-router ready!

Name Link
🔨 Latest commit 7547d86
🔍 Latest deploy log https://app.netlify.com/projects/kitbag-router/deploys/698f59e1135f1300087772d0
😎 Deploy Preview https://deploy-preview-699--kitbag-router.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

@pleek91 pleek91 left a comment

Choose a reason for hiding this comment

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

I could have sworn this is how it worked all along. Did we lose this when we did the url refactor maybe?

@stackoverfloweth
Copy link
Copy Markdown
Contributor Author

I could have sworn this is how it worked all along. Did we lose this when we did the url refactor maybe?

I know It was like this before the createUrl stuff, not sure if it goes back further

@stackoverfloweth stackoverfloweth merged commit 1626f33 into main Feb 13, 2026
6 checks passed
@stackoverfloweth stackoverfloweth deleted the default-params-always-optional branch February 13, 2026 18:18
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.

2 participants