2022-07-05 02:12:21 +00:00
|
|
|
import {
|
|
|
|
ComponentPropsOptions,
|
|
|
|
ExtractDefaultPropTypes,
|
|
|
|
ExtractPropTypes
|
|
|
|
} from './v3-component-props'
|
2022-06-01 13:55:33 +00:00
|
|
|
import {
|
|
|
|
MethodOptions,
|
|
|
|
ComputedOptions,
|
|
|
|
ComponentOptionsWithoutProps,
|
|
|
|
ComponentOptionsWithArrayProps,
|
2022-07-05 02:12:21 +00:00
|
|
|
ComponentOptionsWithProps,
|
|
|
|
ComponentOptionsMixin,
|
|
|
|
ComponentOptionsBase
|
2022-06-01 13:55:33 +00:00
|
|
|
} from './v3-component-options'
|
2022-07-05 02:12:21 +00:00
|
|
|
import {
|
|
|
|
ComponentPublicInstanceConstructor,
|
|
|
|
CreateComponentPublicInstance
|
|
|
|
} from './v3-component-public-instance'
|
2022-06-01 13:55:33 +00:00
|
|
|
import { Data, HasDefined } from './common'
|
|
|
|
import { EmitsOptions } from './v3-setup-context'
|
2022-07-08 03:18:36 +00:00
|
|
|
import { CreateElement, RenderContext } from './umd'
|
2022-06-01 13:55:33 +00:00
|
|
|
|
2022-08-18 07:23:47 +00:00
|
|
|
export type DefineComponent<
|
2022-07-05 02:12:21 +00:00
|
|
|
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,
|
|
|
|
Props = Readonly<
|
|
|
|
PropsOrPropOptions extends ComponentPropsOptions
|
|
|
|
? ExtractPropTypes<PropsOrPropOptions>
|
|
|
|
: PropsOrPropOptions
|
|
|
|
>,
|
|
|
|
Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>
|
|
|
|
> = ComponentPublicInstanceConstructor<
|
|
|
|
CreateComponentPublicInstance<
|
|
|
|
Props,
|
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C,
|
|
|
|
M,
|
|
|
|
Mixin,
|
|
|
|
Extends,
|
|
|
|
E,
|
|
|
|
Props,
|
|
|
|
Defaults,
|
|
|
|
true
|
|
|
|
> &
|
|
|
|
Props
|
|
|
|
> &
|
|
|
|
ComponentOptionsBase<
|
|
|
|
Props,
|
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C,
|
|
|
|
M,
|
|
|
|
Mixin,
|
|
|
|
Extends,
|
|
|
|
E,
|
|
|
|
EE,
|
|
|
|
Defaults
|
|
|
|
> & {
|
|
|
|
props: PropsOrPropOptions
|
|
|
|
}
|
|
|
|
|
2022-06-01 13:55:33 +00:00
|
|
|
/**
|
|
|
|
* overload 1: object format with no props
|
|
|
|
*/
|
|
|
|
export function defineComponent<
|
|
|
|
RawBindings,
|
2022-08-19 04:22:51 +00:00
|
|
|
D = {},
|
2022-06-01 13:55:33 +00:00
|
|
|
C extends ComputedOptions = {},
|
|
|
|
M extends MethodOptions = {},
|
2022-07-05 02:12:21 +00:00
|
|
|
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
|
|
|
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
2022-06-01 13:55:33 +00:00
|
|
|
Emits extends EmitsOptions = {},
|
|
|
|
EmitsNames extends string = string
|
|
|
|
>(
|
2022-08-15 01:53:12 +00:00
|
|
|
options: { functional?: never } & ComponentOptionsWithoutProps<
|
2022-06-01 13:55:33 +00:00
|
|
|
{},
|
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C,
|
|
|
|
M,
|
|
|
|
Mixin,
|
|
|
|
Extends,
|
|
|
|
Emits,
|
|
|
|
EmitsNames
|
|
|
|
>
|
2022-07-05 02:12:21 +00:00
|
|
|
): DefineComponent<{}, RawBindings, D, C, M, Mixin, Extends, Emits>
|
|
|
|
|
2022-06-01 13:55:33 +00:00
|
|
|
/**
|
|
|
|
* overload 2: 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,
|
2022-08-19 04:22:51 +00:00
|
|
|
RawBindings = {},
|
|
|
|
D = {},
|
2022-06-01 13:55:33 +00:00
|
|
|
C extends ComputedOptions = {},
|
|
|
|
M extends MethodOptions = {},
|
2022-07-05 02:12:21 +00:00
|
|
|
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
|
|
|
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
2022-06-01 13:55:33 +00:00
|
|
|
Emits extends EmitsOptions = {},
|
|
|
|
EmitsNames extends string = string,
|
|
|
|
PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
|
|
|
|
>(
|
2022-08-15 01:53:12 +00:00
|
|
|
options: { functional?: never } & ComponentOptionsWithArrayProps<
|
2022-06-01 13:55:33 +00:00
|
|
|
PropNames,
|
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C,
|
|
|
|
M,
|
|
|
|
Mixin,
|
|
|
|
Extends,
|
|
|
|
Emits,
|
|
|
|
EmitsNames
|
|
|
|
>
|
2022-07-05 02:12:21 +00:00
|
|
|
): DefineComponent<
|
2022-06-01 13:55:33 +00:00
|
|
|
Readonly<{ [key in PropNames]?: any }>,
|
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C,
|
|
|
|
M,
|
|
|
|
Mixin,
|
|
|
|
Extends,
|
|
|
|
Emits
|
|
|
|
>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* overload 3: object format with object props declaration
|
|
|
|
*
|
|
|
|
* see `ExtractPropTypes` in './componentProps.ts'
|
|
|
|
*/
|
|
|
|
export function defineComponent<
|
|
|
|
Props,
|
2022-08-19 04:22:51 +00:00
|
|
|
RawBindings = {},
|
|
|
|
D = {},
|
2022-06-01 13:55:33 +00:00
|
|
|
C extends ComputedOptions = {},
|
|
|
|
M extends MethodOptions = {},
|
2022-07-05 02:12:21 +00:00
|
|
|
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
|
|
|
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
2022-06-01 13:55:33 +00:00
|
|
|
Emits extends EmitsOptions = {},
|
|
|
|
EmitsNames extends string = string,
|
|
|
|
PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
|
|
|
|
>(
|
|
|
|
options: HasDefined<Props> extends true
|
2022-08-15 01:53:12 +00:00
|
|
|
? { functional?: never } & ComponentOptionsWithProps<
|
2022-06-01 13:55:33 +00:00
|
|
|
PropsOptions,
|
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C,
|
|
|
|
M,
|
|
|
|
Mixin,
|
|
|
|
Extends,
|
|
|
|
Emits,
|
|
|
|
EmitsNames,
|
|
|
|
Props
|
|
|
|
>
|
2022-08-15 01:53:12 +00:00
|
|
|
: { functional?: never } & ComponentOptionsWithProps<
|
2022-06-01 13:55:33 +00:00
|
|
|
PropsOptions,
|
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C,
|
|
|
|
M,
|
|
|
|
Mixin,
|
|
|
|
Extends,
|
|
|
|
Emits,
|
|
|
|
EmitsNames
|
|
|
|
>
|
2022-07-05 02:12:21 +00:00
|
|
|
): DefineComponent<PropsOptions, RawBindings, D, C, M, Mixin, Extends, Emits>
|
2022-08-15 01:53:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* overload 4.1: functional component with array props
|
|
|
|
*/
|
|
|
|
export function defineComponent<
|
|
|
|
PropNames extends string,
|
|
|
|
Props = Readonly<{ [key in PropNames]?: any }>
|
|
|
|
>(options: {
|
|
|
|
functional: true
|
|
|
|
props?: PropNames[]
|
|
|
|
render?: (h: CreateElement, context: RenderContext<Props>) => any
|
|
|
|
}): DefineComponent<Props>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* overload 4.2: functional component with object props
|
|
|
|
*/
|
|
|
|
export function defineComponent<
|
|
|
|
PropsOptions extends ComponentPropsOptions = ComponentPropsOptions,
|
|
|
|
Props = ExtractPropTypes<PropsOptions>
|
|
|
|
>(options: {
|
|
|
|
functional: true
|
|
|
|
props?: PropsOptions
|
|
|
|
render?: (h: CreateElement, context: RenderContext<Props>) => any
|
|
|
|
}): DefineComponent<PropsOptions>
|