Skip to content

feat: strongly typed props when render vue component#1773

Closed
Waleed-KH wants to merge 1 commit into
maizzle:masterfrom
Waleed-KH:ts-props
Closed

feat: strongly typed props when render vue component#1773
Waleed-KH wants to merge 1 commit into
maizzle:masterfrom
Waleed-KH:ts-props

Conversation

@Waleed-KH

@Waleed-KH Waleed-KH commented Jul 1, 2026

Copy link
Copy Markdown

This pull request enhances type safety and flexibility when rendering Vue components by improving how props are typed and passed to components. The changes introduce generic typing for the render function and the MaizzleConfig interface, ensuring that props are strongly typed throughout the rendering process. Additionally, a new test verifies that props are correctly passed to strongly typed components.

Type safety and API improvements:

  • The render function in src/render/index.ts now supports generic typing for Vue components, allowing props to be strongly typed using ComponentProps<TComponent>. This ensures better type inference and developer experience when rendering components. [1] [2]
  • The MaizzleConfig interface in src/types/config.ts is now generic, enabling the props field to be typed according to the component's expected props rather than always being Record<string, any>. [1] [2]

Dependency updates:

  • Added the vue-component-type-helpers package to package.json to provide improved type utilities for Vue component props.

Testing:

  • Added a new test in src/tests/render/props.test.ts to verify that props are correctly passed to a strongly typed Vue component, ensuring the new generic typing works as intended. [1] [2]

Summary by CodeRabbit

  • New Features
    • Improved type support for rendering Vue components, including stronger typing for passed props.
    • Added support for generic config typing so component props can be validated more precisely.
  • Tests
    • Added coverage for rendering a typed component with multiple prop types and verifying the output.
  • Dependencies
    • Added a new runtime dependency to support the updated type handling.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

MaizzleConfig is made generic over a TProps type parameter, allowing the props field to be strongly typed. The render() function gains overloads that derive config prop typing from a rendered Vue component via ComponentProps. A new dependency and a test validating typed rendering were also added.

Changes

Typed Props for render()

Layer / File(s) Summary
Generic MaizzleConfig props type
src/types/config.ts
MaizzleConfig becomes generic with a TProps parameter defaulting to Record<string, any>; the props field type changes from a fixed type to TProps.
render() overloads using ComponentProps
src/render/index.ts
Imports ComponentProps and adds typed overloads/implementation so rendering a component types config via ComponentProps<TComponent>, while string-template rendering keeps the generic MaizzleConfig typing.
Dependency and typed rendering test
package.json, src/tests/render/props.test.ts
Adds vue-component-type-helpers dependency and a new test using defineComponent/PropType to verify typed props render correctly in output HTML.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

Not applicable — the changes are type-system enhancements and a test addition without multi-component runtime interactions warranting a sequence diagram.

Suggested labels: enhancement, typescript

Suggested reviewers: maizzle-maintainers

🐰 A prop, a type, a helper small,
Now render() knows the shape of all—
Vue components dressed in typed attire,
Config follows what the props require,
Hop hop, TypeScript smiles at the code review call.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding stronger typing for Vue component props during render.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cossssmin cossssmin closed this Jul 1, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/render/index.ts`:
- Around line 26-42: The overload split in render is rejecting union-typed
callers, so add a union-compatible overload for render that accepts template as
string | Component (or restore the broader signature) while keeping the existing
string and generic Component overloads. Make sure the new signature is alongside
the render function declarations so TypeScript can resolve callers whose
template variable is typed as a union.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 41946957-594e-4746-a63c-ff0c108bdaea

📥 Commits

Reviewing files that changed from the base of the PR and between d5685d3 and 274aac9.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • package.json
  • src/render/index.ts
  • src/tests/render/props.test.ts
  • src/types/config.ts

Comment thread src/render/index.ts
Comment on lines +26 to +42
export async function render<TComponent extends Component>(
component: TComponent,
config?: Partial<MaizzleConfig<ComponentProps<TComponent>>>,
): Promise<RenderResult>;

/**
* Render a Vue SFC email template to a fully-transformed HTML string.
* Accepts a file path or a raw SFC source string.
*/
export async function render(
template: string | Component,
template: string,
config?: Partial<MaizzleConfig>,
): Promise<RenderResult>;

export async function render<TComponent extends Component>(
template: string | TComponent,
config?: Partial<MaizzleConfig<ComponentProps<TComponent>>>,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for render() call sites that might pass a union-typed template variable
rg -nP -C4 '\brender\s*\(' src --type=ts -g '!**/tests/**'

Repository: maizzle/framework

Length of output: 9298


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the public render overloads, the Component type, and any call sites/usages
sed -n '1,140p' src/render/index.ts
printf '\n--- Component type ---\n'
rg -n "export (type|interface) Component|type Component|interface Component" src -g '*.ts'
printf '\n--- render() call sites/usages ---\n'
rg -n "\brender\s*\(" src test tests examples docs -g '*.ts' -g '*.tsx' -g '*.js' -g '*.mjs' -g '*.cjs' -g '*.md'
printf '\n--- union-typed candidates near render calls ---\n'
rg -n -C 2 ":\s*string\s*\|\s*Component|:\s*Component\s*\|\s*string|as\s*string\s*\|\s*Component|as\s*Component\s*\|\s*string" src test tests examples docs -g '*.ts' -g '*.tsx'

Repository: maizzle/framework

Length of output: 42280


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Look for explicit union-typed template variables that could hit the overload gap
rg -n -C 2 "string\s*\|\s*Component|Component\s*\|\s*string" src src/tests -g '*.ts' -g '*.tsx'

printf '\n--- render() call sites with local template variables ---\n'
rg -n -C 2 "const\s+\w+\s*=\s*.*\n.*\brender\s*\(\s*\w+\s*[,)]" src src/tests -g '*.ts' -g '*.tsx'

Repository: maizzle/framework

Length of output: 1230


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find explicit union-typed variables/usages relevant to render()
rg -n -C 2 "string\s*\|\s*Component|Component\s*\|\s*string" src src/tests -g '*.ts' -g '*.tsx' || true

printf '\n--- render() calls with non-literal arguments ---\n'
rg -n -C 1 "\brender\s*\(\s*[A-Za-z_][A-Za-z0-9_]*\s*[,)]" src src/tests -g '*.ts' -g '*.tsx' || true

Repository: maizzle/framework

Length of output: 3524


Keep a union-compatible overload. The split overloads reject callers whose template variable is typed string | Component, so existing TypeScript consumers with a union-typed template will stop compiling. Add an overload that accepts the union directly, or keep the previous broad signature.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/render/index.ts` around lines 26 - 42, The overload split in render is
rejecting union-typed callers, so add a union-compatible overload for render
that accepts template as string | Component (or restore the broader signature)
while keeping the existing string and generic Component overloads. Make sure the
new signature is alongside the render function declarations so TypeScript can
resolve callers whose template variable is typed as a union.

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