Skip to content

feat(types): Add const modifier to literal parsers to auto-infer their arguments as literals#1038

Merged
franky47 merged 8 commits into47ng:nextfrom
neefrehman:feauture/const-literal-parsers
Jul 9, 2025
Merged

feat(types): Add const modifier to literal parsers to auto-infer their arguments as literals#1038
franky47 merged 8 commits into47ng:nextfrom
neefrehman:feauture/const-literal-parsers

Conversation

@neefrehman
Copy link
Contributor

@neefrehman neefrehman commented Jul 6, 2025

I often have to add the as const modifier to arrays of strings or numbers to get the types to work properly, as is also suggested by the docs. I thought it was worth opening this PR that adds a const modifier to the type parameters for the literals, so that it can automatically do this. I've also updated a handful of examples and docs to illustrate the simpler usage.

Hopefully the you agree that it's a nice type enhancement @franky47, but feel free to close this PR if not :)

@vercel
Copy link

vercel bot commented Jul 6, 2025

@neefrehman is attempting to deploy a commit to the 47ng Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Jul 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nuqs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 9, 2025 11:46am

@neefrehman neefrehman changed the title feat(types): Allow literal parser to auto-as-const arguments feat(types): Allow literal parsers to auto-as-const arguments Jul 6, 2025
@franky47
Copy link
Member

franky47 commented Jul 6, 2025

I had read about that const modifier in generics when it came out but it didn't occur to me to use it here, thanks for the suggestion, it's a nice improvement!

@franky47 franky47 added this to the 🪵 Backlog milestone Jul 6, 2025
@franky47 franky47 added the parsers/built-in Related to built-in parsers label Jul 6, 2025
@neefrehman neefrehman changed the title feat(types): Allow literal parsers to auto-as-const arguments feat(types): Add const modifier to literal parsers to automatically infer their arguments as literals Jul 7, 2025
@neefrehman neefrehman changed the title feat(types): Add const modifier to literal parsers to automatically infer their arguments as literals feat(types): Add const modifier to literal parsers to infer their arguments as literals Jul 7, 2025
@neefrehman neefrehman changed the title feat(types): Add const modifier to literal parsers to infer their arguments as literals feat(types): Add const modifier to literal parsers to auto-infer their arguments as literals Jul 7, 2025
@franky47 franky47 added the deploy:preview Deploy a preview version of this PR on pkg.pr.new label Jul 9, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 9, 2025

pnpm add https://pkg.pr.new/nuqs@1038

commit: be2e999

@franky47 franky47 merged commit 97a90e8 into 47ng:next Jul 9, 2025
27 checks passed
@github-actions
Copy link

github-actions bot commented Aug 8, 2025

🎉 This PR is included in version 2.5.0-beta.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This PR is included in version 2.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

deploy:preview Deploy a preview version of this PR on pkg.pr.new parsers/built-in Related to built-in parsers released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants