Skip to content

Commit ff75eb7

Browse files
committed
feat(macros): support generic components
1 parent f1f6236 commit ff75eb7

File tree

4 files changed

+473
-507
lines changed

4 files changed

+473
-507
lines changed

packages/macros/src/volar/transform.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ export function transformJsxMacros(
2222
if (asyncModifier && macros.defineComponent)
2323
codes.replaceRange(asyncModifier.pos, asyncModifier.end)
2424
const result =
25-
macros.defineComponent && root.typeParameters?.length
26-
? '({}) as JSX.Element'
27-
: '__ctx.render'
25+
'({}) as typeof __ctx.render & { __ctx?: { props: typeof __ctx.props } & typeof __ctx.context }'
2826

2927
const propsType = root.parameters[0]?.type
3028
? root.parameters[0].type.getText(ast)
@@ -97,10 +95,10 @@ export function transformJsxMacros(
9795
return {} as {
9896
props: {${props.join(', ')}},
9997
context: ${
100-
root.parameters[1]?.type ? root.parameters[1].type.getText(ast) : '{}'
101-
} & {
98+
root.parameters[1]?.type ? `${root.parameters[1].type.getText(ast)} & ` : ''
99+
}{
102100
slots: ${macros.defineSlots ?? '{}'},
103-
expose: (exposed: ${macros.defineExpose ?? '{}'}) => void,
101+
expose: (exposed: ${macros.defineExpose ?? 'Record<string, any>'}) => void,
104102
attrs: Record<string, any>
105103
},
106104
render: typeof __render

packages/runtime/src/vue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export declare class VaporComponentInstance<
9191
expose: (<T extends Record<string, any> = Exposed>(exposed: T) => void) &
9292
string[]
9393
exposed: Exposed | null
94-
exposeProxy: ShallowUnwrapRef<Exposed> | null
94+
exposeProxy: Prettify<ShallowUnwrapRef<Exposed>> | null
9595
refs: TypeRefs
9696
provides: Record<string, any>
9797
ids: [string, number, number]

0 commit comments

Comments
 (0)