@@ -70,6 +70,31 @@ interface ComponentOptionsWithoutProps<Props = unknown, RawBindings = Data> {
70
70
setup ?: SetupFunction < Props , RawBindings > ;
71
71
}
72
72
73
+ // overload 1: object format with no props
74
+ export function defineComponent < RawBindings > (
75
+ options : ComponentOptionsWithoutProps < unknown , RawBindings >
76
+ ) : VueProxy < unknown , RawBindings > ;
77
+ // overload 2: object format with object props declaration
78
+ // see `ExtractPropTypes` in ./componentProps.ts
79
+ export function defineComponent <
80
+ Props ,
81
+ RawBindings = Data ,
82
+ PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
83
+ > (
84
+ // prettier-ignore
85
+ options : (
86
+ // prefer the provided Props, otherwise infer it from PropsOptions
87
+ HasDefined < Props > extends true
88
+ ? ComponentOptionsWithProps < PropsOptions , RawBindings , Props >
89
+ : ComponentOptionsWithProps < PropsOptions , RawBindings > ) &
90
+ Omit < Vue2ComponentOptions < Vue > , keyof ComponentOptionsWithProps < never , never > >
91
+ ) : VueProxy < PropsOptions , RawBindings > ;
92
+ // implementation, close to no-op
93
+ export function defineComponent ( options : any ) {
94
+ return options as any ;
95
+ }
96
+
97
+ // createComponent is kept around for retro-compatibility
73
98
// overload 1: object format with no props
74
99
export function createComponent < RawBindings > (
75
100
options : ComponentOptionsWithoutProps < unknown , RawBindings >
@@ -89,7 +114,10 @@ export function createComponent<
89
114
: ComponentOptionsWithProps < PropsOptions , RawBindings > ) &
90
115
Omit < Vue2ComponentOptions < Vue > , keyof ComponentOptionsWithProps < never , never > >
91
116
) : VueProxy < PropsOptions , RawBindings > ;
92
- // implementation, close to no-op
117
+ // implementation, deferring to defineComponent, but logging a warning in dev mode
93
118
export function createComponent ( options : any ) {
94
- return options as any ;
119
+ if ( process . env . NODE_ENV !== 'production' ) {
120
+ Vue . util . warn ( '`createComponent` has been renamed to `defineComponent`.' ) ;
121
+ }
122
+ return defineComponent ( options ) ;
95
123
}
0 commit comments