Skip to content

Commit e2d4ec8

Browse files
committed
fix: wrapping functional components
1 parent 374b8b1 commit e2d4ec8

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

packages/dts-test/defineComponent.test-d.tsx

+22
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,28 @@ describe('define attrs', () => {
13801380
/>
13811381
)
13821382
})
1383+
1384+
test('wrap components w/ functional component', () => {
1385+
const Child = defineComponent((props: { foo: string }, ctx) => {
1386+
return () => <div>{props.foo}</div>
1387+
})
1388+
const Comp = defineComponent({
1389+
props: {
1390+
bar: Number
1391+
},
1392+
attrs: Object as AttrsType<typeof Child>,
1393+
created() {
1394+
expectType<unknown>(this.$attrs.class)
1395+
expectType<unknown>(this.$attrs.style)
1396+
},
1397+
render() {
1398+
return <Child {...this.$attrs} />
1399+
}
1400+
})
1401+
expectType<JSX.Element>(
1402+
<Comp class={'str'} style={'str'} bar={1} foo={'str'} />
1403+
)
1404+
})
13831405
})
13841406

13851407
// #5948

packages/runtime-core/src/componentOptions.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ import {
6161
ComponentPublicInstance,
6262
isReservedPrefix,
6363
IntersectionMixin,
64-
UnwrapMixinsType,
65-
ComponentPublicInstanceConstructor
64+
UnwrapMixinsType
6665
} from './componentPublicInstance'
6766
import { warn } from './warning'
6867
import { VNodeChild } from './vnode'
@@ -420,8 +419,10 @@ export type ComponentOptionsMixin = ComponentOptionsBase<
420419

421420
declare const AttrSymbol: unique symbol
422421
export type AttrsType<T extends Record<string, any> = Record<string, any>> = {
423-
[AttrSymbol]?: T extends ComponentPublicInstanceConstructor
424-
? InstanceType<T>['$props']
422+
[AttrSymbol]?: T extends new () => { $props: infer P }
423+
? NonNullable<P>
424+
: T extends (props: infer P, ...args: any) => any
425+
? P
425426
: T
426427
}
427428

0 commit comments

Comments
 (0)