import { ComponentOptionsWithoutProps, ComponentOptionsWithArrayProps, ComponentOptionsWithObjectProps, ComponentOptionsBase, ComponentOptionsMixin, AttrsType, UnwrapAttrsType, ExtractPropsAndEvents } from './componentOptions' export { ComponentOptionsWithoutProps, ComponentOptionsWithArrayProps, ComponentOptionsWithObjectProps, ComponentOptionsBase, ComponentOptionsMixin, AttrsType, UnwrapAttrsType, } from './componentOptions' import { SetupContext, AllowedComponentProps, ComponentCustomProps, HasDefinedAttrs } from './component' import { ExtractPropTypes, ComponentPropsOptions, ExtractDefaultPropTypes, VNodeProps, ComputedOptions, MethodOptions, RenderFunction, ComponentInjectOptions, } from '@vue/runtime-core' import { EmitsOptions, EmitsToProps } from './componentEmits' import { isFunction } from '@vue/shared' import { CreateComponentPublicInstance, ComponentPublicInstanceConstructor } from './componentPublicInstance' import { SlotsType } from './componentSlots' import { ComponentObjectPropsOptions, ComponentOptions } from 'vue' import { CreateElement, RenderContext } from 'vue2' export type { SetupContext, ExtractPropsAndEvents }; export type PublicProps = VNodeProps & AllowedComponentProps & ComponentCustomProps export type DefineComponent< PropsOrPropOptions = {}, RawBindings = {}, D = {}, C extends ComputedOptions = ComputedOptions, M extends MethodOptions = MethodOptions, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = {}, EE extends string = string, S extends SlotsType = {}, Attrs extends AttrsType = Record, PP = PublicProps, Props = Readonly< PropsOrPropOptions extends ComponentPropsOptions ? ExtractPropTypes : PropsOrPropOptions > & ({} extends E ? {} : EmitsToProps), Defaults = ExtractDefaultPropTypes > = ComponentPublicInstanceConstructor< CreateComponentPublicInstance< Props, RawBindings, D, C, M, Mixin, Extends, E, PP & Props, Defaults, true, {}, S, Attrs > & Props > & ComponentOptionsBase< Props, RawBindings, D, C, M, Mixin, Extends, E, EE, Defaults > & PP // defineComponent is a utility that is primarily used for type inference // when declaring components. Type inference is provided in the component // options (provided as the argument). The returned value has artificial types // for TSX / manual render function / IDE support. // overload 1: direct setup function // (uses user defined props interface) export function defineComponent< Props extends Record, E extends EmitsOptions = {}, EE extends string = string, S extends SlotsType = {}, Attrs extends AttrsType = Record, PropsAttrs = HasDefinedAttrs extends true ? UnwrapAttrsType> : {} >( setup: ( props: Props, ctx: SetupContext ) => RenderFunction | Promise, options?: Pick & { props?: (keyof Props)[] emits?: E | EE[] slots?: S attrs?: Attrs } ): (props: Props & EmitsToProps & PropsAttrs) => any export function defineComponent< Props extends Record, E extends EmitsOptions = {}, EE extends string = string, S extends SlotsType = {} >( setup: ( props: Props, ctx: SetupContext ) => RenderFunction | Promise, options?: Pick & { props?: ComponentObjectPropsOptions emits?: E | EE[] slots?: S } ): (props: Props & EmitsToProps) => any // overload 2: object format with no props // (uses user defined props interface) // return type is for Vetur and TSX support export function defineComponent< Props = {}, RawBindings = {}, D = {}, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = {}, EE extends string = string, I extends ComponentInjectOptions = {}, II extends string = string, S extends SlotsType = {}, Attrs extends AttrsType = Record >( comp: ComponentOptionsWithoutProps< Props, RawBindings, D, C, M, Mixin, Extends, E, EE, I, II, S, Attrs > ): DefineComponent // overload 3: object format with array props declaration // props inferred as { [key in PropNames]?: any } // return type is for Vetur and TSX support export function defineComponent< PropNames extends string, RawBindings, D, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = {}, EE extends string = string, I extends ComponentInjectOptions = {}, II extends string = string, S extends SlotsType = {}, Attrs extends AttrsType = Record >( comp: ComponentOptionsWithArrayProps< PropNames, RawBindings, D, C, M, Mixin, Extends, E, EE, I, II, S, Attrs > & { functional?: undefined } ): DefineComponent< Readonly<{ [key in PropNames]?: any }>, RawBindings, D, C, M, Mixin, Extends, E, EE, S, Attrs > // overload 4: object format with object props declaration // see `ExtractPropTypes` in ./componentProps.ts export function defineComponent< // the Readonly constraint allows TS to treat the type of { required: true } // as constant instead of boolean. PropsOptions extends Readonly, RawBindings, D, C extends ComputedOptions = {}, M extends MethodOptions = {}, Mixin extends ComponentOptionsMixin = ComponentOptionsMixin, Extends extends ComponentOptionsMixin = ComponentOptionsMixin, E extends EmitsOptions = {}, EE extends string = string, I extends ComponentInjectOptions = {}, II extends string = string, S extends SlotsType = {}, Attrs extends AttrsType = Record >( comp: ComponentOptionsWithObjectProps< PropsOptions, RawBindings, D, C, M, Mixin, Extends, E, EE, I, II, S, Attrs > & { functional?: undefined } ): DefineComponent< PropsOptions, RawBindings, D, C, M, Mixin, Extends, E, EE, S, Attrs > /** * overload 4.1: functional component with array props in Vue2 */ export function defineComponent< PropNames extends string, Props = Readonly<{ [key in PropNames]?: any }>, Attrs extends AttrsType = Record, // AttrsProps type used for JSX validation of attrs AttrsProps = HasDefinedAttrs extends true // if attrs is not defined ? Omit, keyof Props> // exclude props from attrs, for JSX validation : {} // no JSX validation of attrs >(options: { functional: true props?: PropNames[] attrs?: Attrs, render?: (h: CreateElement, context: RenderContext & { attrs: HasDefinedAttrs extends true ? UnwrapAttrsType> : Record }) => any }): DefineComponent /** * overload 4.2: functional component with object props in Vue2 */ export function defineComponent< PropsOptions extends ComponentPropsOptions = ComponentPropsOptions, Props = ExtractPropTypes, Attrs extends AttrsType = Record, // AttrsProps type used for JSX validation of attrs AttrsProps = HasDefinedAttrs extends true // if attrs is not defined ? Omit, keyof Props> // exclude props from attrs, for JSX validation : {} // no JSX validation of attrs >(options: { functional: true props?: PropsOptions attrs?: Attrs, render?: (h: CreateElement, context: RenderContext & { attrs: HasDefinedAttrs extends true ? UnwrapAttrsType> : Record }) => any }): DefineComponent // implementation, close to no-op /*! #__NO_SIDE_EFFECTS__ */ export function defineComponent( options: unknown, extraOptions?: ComponentOptions ) { return isFunction(options) ? // #8326: extend call and options.name access are considered side-effects // by Rollup, so we have to wrap it in a pure-annotated IIFE. /*#__PURE__*/ (() => Object.assign({ name: options.name }, extraOptions, { setup: options }))() : options }