feat(next-typed-href): add branded option to return TypedHref from $href()#83
Merged
Conversation
…ref()
Introduces TypedHref branded type and branded option to both defineTypedHref and defineTypedHrefWithNuqs. When { branded: true } is passed, $href() returns TypedHref instead of string, enabling type-level distinction from plain strings while preserving backward compatibility.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…re branded option API - Translate Japanese inline comments in JSDoc to English - Change branded option from routes() argument to withOptions() chain for both defineTypedHref and defineTypedHrefWithNuqs, matching the existing withOptions pattern - Narrow branded type to `true` only to preserve literal type inference - Add withOptions() chain to defineTypedHref for consistency with defineTypedHrefWithNuqs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…serve boolean literal Changes branded option type from `true` to `boolean` and adds `const` modifier to withOptions generic so TypeScript preserves the literal type of the argument, ensuring HrefReturn resolves to TypedHref when branded: true is passed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…/branded section
- Fix setup examples to use defineTypedHref.routes<>() and
defineTypedHrefWithNuqs.routes<>().nuqs({}) (old API was outdated)
- Add TypedHref section explaining branded return type and withOptions usage
- Add withOptions section covering requiredSearchParams and branded options
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
akameco
approved these changes
May 27, 2026
Contributor
akameco
left a comment
There was a problem hiding this comment.
テスト確認OK。LGTM〜
imo: src/index.ts の createWithTypedHrefRoutes / WithTypedHrefRoutes と、src/nuqs.ts の createWithRoutes / WithRoutes で、ほぼ同じ役割の関数・型なのに命名が分かれているのがちょっと気になる。
両方ともファイル内ローカル(export していない)ため名前空間の衝突は無いので合わせてしまっていいと思う。
Member
Author
|
Linear issue 起票したのであとまわし: https://linear.app/plainbrew/issue/PC-122 |
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.
Summary
TypedHrefbranded type (string & { readonly __brand: "TypedHref" }) をcommon/types.tsに追加defineTypedHref.routes<R, M>({ branded: true })で$href()の戻り値がTypedHrefになるよう対応defineTypedHrefWithNuqs.routes<R, M>().withOptions({ branded: true }).nuqs({})でも同様に対応stringのまま — 後方互換を保持TypedHrefはstringのサブタイプなので既存コードへの影響なしTest plan
pnpm --filter @plainbrew/next-typed-href type-checkpnpm --filter @plainbrew/next-typed-href test:run(55テスト通過)branded: true時に$href()がTypedHrefを返すことを型レベルで検証brandedなしで既存コードが壊れないことを確認Closes PC-121
🤖 Generated with Claude Code