@@ -56,7 +56,7 @@ export type SetupFunction<Props, RawBindings> = (
56
56
ctx : SetupContext
57
57
) => RawBindings | RenderFunction < Props > ;
58
58
59
- export interface ComponentOptions <
59
+ interface ComponentOptions <
60
60
PropsOptions = ComponentPropsOptions ,
61
61
RawBindings = Data ,
62
62
Props = ExtractPropTypes < PropsOptions >
@@ -65,10 +65,23 @@ export interface ComponentOptions<
65
65
setup ?: SetupFunction < Props , RawBindings > ;
66
66
}
67
67
68
+ // Conditional returns can enforce identical types.
69
+ // See here: https://github.com/Microsoft/TypeScript/issues/27024#issuecomment-421529650
70
+ // prettier-ignore
71
+ type Equal < Left , Right > =
72
+ ( < U > ( ) => U extends Left ? 1 : 0 ) extends ( < U > ( ) => U extends Right ? 1 : 0 ) ? true : false ;
73
+
74
+ type HasDefined < T > = Equal < T , unknown > extends true ? false : true ;
75
+
68
76
// object format with object props declaration
69
77
// see `ExtractPropTypes` in ./componentProps.ts
70
- export function createComponent < PropsOptions , RawBindings > (
71
- options : ComponentOptions < PropsOptions , RawBindings > &
78
+ export function createComponent < Props , RawBindings = Data , PropsOptions = ComponentPropsOptions > (
79
+ // prettier-ignore
80
+ options : (
81
+ // prefer the provided Props, otherwise infer it from PropsOptions
82
+ HasDefined < Props > extends true
83
+ ? ComponentOptions < PropsOptions , RawBindings , Props >
84
+ : ComponentOptions < PropsOptions , RawBindings > ) &
72
85
Omit < Vue2ComponentOptions < Vue > , keyof ComponentOptions < never , never > >
73
86
) : VueProxy < PropsOptions , RawBindings > ;
74
87
// implementation, close to no-op
0 commit comments