vue/types/v3-define-component.d.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

202 lines
4.7 KiB
TypeScript
Raw Normal View History

import {
ComponentPropsOptions,
ExtractDefaultPropTypes,
ExtractPropTypes
} from './v3-component-props'
2022-06-01 13:55:33 +00:00
import {
MethodOptions,
ComputedOptions,
ComponentOptionsWithoutProps,
ComponentOptionsWithArrayProps,
ComponentOptionsWithProps,
ComponentOptionsMixin,
ComponentOptionsBase
2022-06-01 13:55:33 +00:00
} from './v3-component-options'
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'
import { CreateElement, RenderContext } from './umd'
2022-06-01 13:55:33 +00:00
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,
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,
D = {},
2022-06-01 13:55:33 +00:00
C extends ComputedOptions = {},
M extends MethodOptions = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
2022-06-01 13:55:33 +00:00
Emits extends EmitsOptions = {},
EmitsNames extends string = string
>(
options: { functional?: never } & ComponentOptionsWithoutProps<
2022-06-01 13:55:33 +00:00
{},
RawBindings,
D,
C,
M,
Mixin,
Extends,
Emits,
EmitsNames
>
): 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,
RawBindings = {},
D = {},
2022-06-01 13:55:33 +00:00
C extends ComputedOptions = {},
M extends MethodOptions = {},
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: { functional?: never } & ComponentOptionsWithArrayProps<
2022-06-01 13:55:33 +00:00
PropNames,
RawBindings,
D,
C,
M,
Mixin,
Extends,
Emits,
EmitsNames
>
): 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,
RawBindings = {},
D = {},
2022-06-01 13:55:33 +00:00
C extends ComputedOptions = {},
M extends MethodOptions = {},
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
? { functional?: never } & ComponentOptionsWithProps<
2022-06-01 13:55:33 +00:00
PropsOptions,
RawBindings,
D,
C,
M,
Mixin,
Extends,
Emits,
EmitsNames,
Props
>
: { functional?: never } & ComponentOptionsWithProps<
2022-06-01 13:55:33 +00:00
PropsOptions,
RawBindings,
D,
C,
M,
Mixin,
Extends,
Emits,
EmitsNames
>
): DefineComponent<PropsOptions, RawBindings, D, C, M, Mixin, Extends, Emits>
/**
* 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>