import { ComputedOptions, MethodOptions, ComponentOptionsWithoutProps, ComponentOptionsWithArrayProps, ComponentOptionsWithObjectProps } from './apiOptions' import { SetupContext, RenderFunction } from './component' import { ComponentPublicInstance } from './componentProxy' import { ExtractPropTypes } from './componentProps' import { isFunction } from '@vue/shared' // overload 1: direct setup function // (uses user defined props interface) export function createComponent( setup: (props: Props, ctx: SetupContext) => RawBindings | RenderFunction ): { new (): ComponentPublicInstance } // overload 2: object format with no props // (uses user defined props interface) // return type is for Vetur and TSX support export function createComponent< Props, RawBindings, D, C extends ComputedOptions = {}, M extends MethodOptions = {} >( options: ComponentOptionsWithoutProps ): { new (): ComponentPublicInstance } // overload 3: object format with array props declaration // props inferred as { [key in PropNames]?: unknown } // return type is for Vetur and TSX support export function createComponent< PropNames extends string, RawBindings, D, C extends ComputedOptions = {}, M extends MethodOptions = {} >( options: ComponentOptionsWithArrayProps ): { new (): ComponentPublicInstance< { [key in PropNames]?: unknown }, RawBindings, D, C, M > } // overload 4: object format with object props declaration // see `ExtractPropTypes` in ./componentProps.ts export function createComponent< PropsOptions, RawBindings, D, C extends ComputedOptions = {}, M extends MethodOptions = {} >( options: ComponentOptionsWithObjectProps ): { // for Vetur and TSX support new (): ComponentPublicInstance< ExtractPropTypes, RawBindings, D, C, M, ExtractPropTypes > } // implementation, close to no-op export function createComponent(options: unknown) { return isFunction(options) ? { setup: options } : options }