File tree 2 files changed +61
-0
lines changed
2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -1079,3 +1079,39 @@ export default {
1079
1079
}
1080
1080
} )
1081
1081
}
1082
+
1083
+ describe ( 'functional w/ array props' , ( ) => {
1084
+ const Foo = defineComponent ( {
1085
+ functional : true ,
1086
+ props : [ 'foo' ] ,
1087
+ render ( h , ctx ) {
1088
+ ctx . props . foo
1089
+ // @ts -expect-error
1090
+ ctx . props . bar
1091
+ }
1092
+ } )
1093
+
1094
+ ; < Foo foo = "hi" />
1095
+ // @ts -expect-error
1096
+ ; < Foo bar = { 123 } />
1097
+ } )
1098
+
1099
+ describe ( 'functional w/ object props' , ( ) => {
1100
+ const Foo = defineComponent ( {
1101
+ functional : true ,
1102
+ props : {
1103
+ foo : String
1104
+ } ,
1105
+ render ( h , ctx ) {
1106
+ ctx . props . foo
1107
+ // @ts -expect-error
1108
+ ctx . props . bar
1109
+ }
1110
+ } )
1111
+
1112
+ ; < Foo foo = "hi" />
1113
+ // @ts -expect-error
1114
+ ; < Foo foo = { 123 } />
1115
+ // @ts -expect-error
1116
+ ; < Foo bar = { 123 } />
1117
+ } )
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
18
18
} from './v3-component-public-instance'
19
19
import { Data , HasDefined } from './common'
20
20
import { EmitsOptions } from './v3-setup-context'
21
+ import { CreateElement , RenderContext } from './umd'
21
22
22
23
type DefineComponent <
23
24
PropsOrPropOptions = { } ,
@@ -66,6 +67,30 @@ type DefineComponent<
66
67
props : PropsOrPropOptions
67
68
}
68
69
70
+ /**
71
+ * overload 0.0: functional component with array props
72
+ */
73
+ export function defineComponent <
74
+ PropNames extends string ,
75
+ Props = Readonly < { [ key in PropNames ] ?: any } >
76
+ > ( options : {
77
+ functional : true
78
+ props ?: PropNames [ ]
79
+ render ?: ( h : CreateElement , context : RenderContext < Props > ) => any
80
+ } ) : DefineComponent < Props >
81
+
82
+ /**
83
+ * overload 0.1: functional component with object props
84
+ */
85
+ export function defineComponent <
86
+ PropsOptions extends ComponentPropsOptions = ComponentPropsOptions ,
87
+ Props = ExtractPropTypes < PropsOptions >
88
+ > ( options : {
89
+ functional : true
90
+ props ?: PropsOptions
91
+ render ?: ( h : CreateElement , context : RenderContext < Props > ) => any
92
+ } ) : DefineComponent < PropsOptions >
93
+
69
94
/**
70
95
* overload 1: object format with no props
71
96
*/
You can’t perform that action at this time.
0 commit comments