fix(types): make templateParams extensible via module augmentation#679
Conversation
Add `templateParams` to `SchemaAugmentations` and intersect it into
`ResolvableTemplateParams`, allowing users to extend templateParams
via `declare module 'unhead/types' { interface SchemaAugmentations { templateParams: { foo: string } } }`.
Also updates `ReactiveHead.templateParams` in the Vue package to use
the shared `ResolvableTemplateParams` type.
Closes #575
📝 WalkthroughWalkthroughAdds a public augmentation interface for template parameters in unhead and updates the Vue package's ReactiveHead.templateParams type to reference the centralized ResolvableTemplateParams, aligning cross-package types for module augmentation. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Bundle Size Analysis
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/unhead/src/types/schema/head.ts (1)
74-86:⚠️ Potential issue | 🟠 MajorTypeScript will reject the documented augmentation pattern due to type incompatibility.
Declaring
templateParams: objectinSchemaAugmentationsprevents consumers from augmenting it with a narrower type like{ siteName: string }. TypeScript's declaration merging rule requires non-function members to have identical types—this pattern will fail with TS2717: "Subsequent property declarations must have the same type".Create a dedicated empty interface for template parameter augmentation and intersect it into both
SchemaAugmentationsandResolvableTemplateParamsinstead. This allows consumers to extend the shape without conflicting with an existing property type.Suggested direction
+export interface TemplateParamsAugmentations {} + export interface SchemaAugmentations { title: TagPriority titleTemplate: TagPriority base: ResolvesDuplicates & TagPriority htmlAttrs: ResolvesDuplicates & TagPriority bodyAttrs: ResolvesDuplicates & TagPriority link: TagPriority & TagPosition & ResolvesDuplicates & ProcessesTemplateParams meta: TagPriority & ResolvesDuplicates & ProcessesTemplateParams style: TagPriority & TagPosition & StringInnerContent & ResolvesDuplicates & ProcessesTemplateParams script: TagPriority & TagPosition & InnerContent & ResolvesDuplicates & ProcessesTemplateParams noscript: TagPriority & TagPosition & StringInnerContent & ResolvesDuplicates & ProcessesTemplateParams - templateParams: object + templateParams: TemplateParamsAugmentations } … -export type ResolvableTemplateParams = { separator?: '|' | '-' | '·' | string } & Record<string, null | string | Record<string, string>> & SchemaAugmentations['templateParams'] +export type ResolvableTemplateParams = + { separator?: '|' | '-' | '·' | string } + & Record<string, null | string | Record<string, string>> + & TemplateParamsAugmentationsConsumers then augment
TemplateParamsAugmentationsdirectly.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/unhead/src/types/schema/head.ts` around lines 74 - 86, Replace the concrete property "templateParams: object" on SchemaAugmentations with a dedicated empty augmentation interface and intersect it where needed: add an empty exported interface TemplateParamsAugmentations {}, remove the templateParams: object declaration from SchemaAugmentations and instead intersect TemplateParamsAugmentations into SchemaAugmentations and into ResolvableTemplateParams (so both types include the augmentable shape). This lets consumers extend TemplateParamsAugmentations (e.g. declare module ... interface TemplateParamsAugmentations { siteName: string }) without triggering TS2717 while preserving existing behavior in SchemaAugmentations and ResolvableTemplateParams.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@packages/unhead/src/types/schema/head.ts`:
- Around line 74-86: Replace the concrete property "templateParams: object" on
SchemaAugmentations with a dedicated empty augmentation interface and intersect
it where needed: add an empty exported interface TemplateParamsAugmentations {},
remove the templateParams: object declaration from SchemaAugmentations and
instead intersect TemplateParamsAugmentations into SchemaAugmentations and into
ResolvableTemplateParams (so both types include the augmentable shape). This
lets consumers extend TemplateParamsAugmentations (e.g. declare module ...
interface TemplateParamsAugmentations { siteName: string }) without triggering
TS2717 while preserving existing behavior in SchemaAugmentations and
ResolvableTemplateParams.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3bff878c-cf07-4266-92f5-78884f306594
📒 Files selected for processing (2)
packages/unhead/src/types/schema/head.tspackages/vue/src/types/schema.ts
|
@copilot can you address code rabbit's issue |
|
@harlan-zw I've opened a new pull request, #684, to work on those changes. Once the pull request is ready, I'll request review from you. |
) * Initial plan * fix(types): use dedicated TemplateParamsAugmentations interface to avoid TS2717 Co-authored-by: harlan-zw <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: harlan-zw <[email protected]>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/unhead/src/types/schema/head.ts (1)
74-75: Consider adding JSDoc to clarify augmentation usage.The empty interface is intentional and correct for TypeScript module augmentation—Biome's warning can be safely ignored here. Adding a brief JSDoc comment would help consumers understand how to extend this interface:
📝 Suggested documentation
+/** + * Augment this interface to add custom template parameter types. + * `@example` + * declare module 'unhead/types' { + * interface TemplateParamsAugmentations { + * siteName: string + * foo?: string + * } + * } + */ export interface TemplateParamsAugmentations {}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/unhead/src/types/schema/head.ts` around lines 74 - 75, Add a concise JSDoc comment above the empty interface TemplateParamsAugmentations explaining that the interface is intentionally empty and provided for TypeScript module augmentation (i.e., consumers should declare module augmentation to extend it), note that tooling warnings (Biome) can be ignored, and include a brief one-line example description of how to extend it so readers know the intended usage and purpose.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/unhead/src/types/schema/head.ts`:
- Around line 74-75: Add a concise JSDoc comment above the empty interface
TemplateParamsAugmentations explaining that the interface is intentionally empty
and provided for TypeScript module augmentation (i.e., consumers should declare
module augmentation to extend it), note that tooling warnings (Biome) can be
ignored, and include a brief one-line example description of how to extend it so
readers know the intended usage and purpose.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6dd6599b-c1bd-488f-aa4f-42b94617e5b6
📒 Files selected for processing (1)
packages/unhead/src/types/schema/head.ts
Summary
templateParamstoSchemaAugmentationsinterface so users can extend it via module augmentationReactiveHead.templateParamsto use the sharedResolvableTemplateParamstypeUsers can now do:
Closes #575
Summary by CodeRabbit