2022-06-01 13:55:33 +00:00
|
|
|
import { Vue } from './vue'
|
|
|
|
import { VNode } from './vnode'
|
|
|
|
import { ComponentOptions as Vue2ComponentOptions } from './options'
|
|
|
|
import { EmitsOptions, SetupContext } from './v3-setup-context'
|
2022-07-05 02:12:21 +00:00
|
|
|
import { Data, LooseRequired, UnionToIntersection } from './common'
|
|
|
|
import {
|
|
|
|
ComponentPropsOptions,
|
|
|
|
ExtractDefaultPropTypes,
|
|
|
|
ExtractPropTypes
|
|
|
|
} from './v3-component-props'
|
|
|
|
import { CreateComponentPublicInstance } from './v3-component-public-instance'
|
2022-06-01 13:55:33 +00:00
|
|
|
export { ComponentPropsOptions } from './v3-component-props'
|
|
|
|
|
2022-07-05 02:12:21 +00:00
|
|
|
/**
|
|
|
|
* Interface for declaring custom options.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```ts
|
|
|
|
* declare module 'vue' {
|
|
|
|
* interface ComponentCustomOptions {
|
|
|
|
* beforeRouteUpdate?(
|
|
|
|
* to: Route,
|
|
|
|
* from: Route,
|
|
|
|
* next: () => void
|
|
|
|
* ): void
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
export interface ComponentCustomOptions {}
|
|
|
|
|
2022-06-01 13:55:33 +00:00
|
|
|
export type ComputedGetter<T> = (ctx?: any) => T
|
|
|
|
export type ComputedSetter<T> = (v: T) => void
|
|
|
|
|
|
|
|
export interface WritableComputedOptions<T> {
|
|
|
|
get: ComputedGetter<T>
|
|
|
|
set: ComputedSetter<T>
|
|
|
|
}
|
|
|
|
|
|
|
|
export type ComputedOptions = Record<
|
|
|
|
string,
|
|
|
|
ComputedGetter<any> | WritableComputedOptions<any>
|
|
|
|
>
|
|
|
|
|
|
|
|
export interface MethodOptions {
|
|
|
|
[key: string]: Function
|
|
|
|
}
|
|
|
|
|
|
|
|
export type SetupFunction<
|
|
|
|
Props,
|
|
|
|
RawBindings = {},
|
|
|
|
Emits extends EmitsOptions = {}
|
|
|
|
> = (
|
|
|
|
this: void,
|
|
|
|
props: Readonly<Props>,
|
|
|
|
ctx: SetupContext<Emits>
|
|
|
|
) => RawBindings | (() => VNode | null) | void
|
|
|
|
|
2022-07-05 02:12:21 +00:00
|
|
|
type ExtractOptionProp<T> = T extends ComponentOptionsBase<
|
|
|
|
infer P, // Props
|
|
|
|
any, // RawBindings
|
|
|
|
any, // D
|
|
|
|
any, // C
|
|
|
|
any, // M
|
|
|
|
any, // Mixin
|
|
|
|
any, // Extends
|
|
|
|
any, // EmitsOptions
|
|
|
|
any // Defaults
|
|
|
|
>
|
|
|
|
? unknown extends P
|
|
|
|
? {}
|
|
|
|
: P
|
|
|
|
: {}
|
|
|
|
|
|
|
|
export interface ComponentOptionsBase<
|
2022-06-01 13:55:33 +00:00
|
|
|
Props,
|
2022-07-05 02:12:21 +00:00
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C extends ComputedOptions,
|
|
|
|
M extends MethodOptions,
|
|
|
|
Mixin extends ComponentOptionsMixin,
|
|
|
|
Extends extends ComponentOptionsMixin,
|
|
|
|
Emits extends EmitsOptions,
|
|
|
|
EmitNames extends string = string,
|
|
|
|
Defaults = {}
|
2022-06-01 13:55:33 +00:00
|
|
|
> extends Omit<
|
2022-07-05 02:12:21 +00:00
|
|
|
Vue2ComponentOptions<Vue, D, M, C, Props>,
|
|
|
|
'data' | 'computed' | 'methods' | 'setup' | 'props' | 'mixins' | 'extends'
|
|
|
|
>,
|
|
|
|
ComponentCustomOptions {
|
2022-08-18 07:32:12 +00:00
|
|
|
// allow any options
|
|
|
|
[key: string]: any
|
|
|
|
|
2022-06-01 13:55:33 +00:00
|
|
|
// rewrite options api types
|
2022-07-05 02:12:21 +00:00
|
|
|
data?: (
|
|
|
|
this: CreateComponentPublicInstance<Props, {}, {}, {}, M, Mixin, Extends>,
|
|
|
|
vm: CreateComponentPublicInstance<Props, {}, {}, {}, M, Mixin, Extends>
|
|
|
|
) => D
|
2022-06-01 13:55:33 +00:00
|
|
|
computed?: C
|
|
|
|
methods?: M
|
2022-07-05 02:12:21 +00:00
|
|
|
mixins?: Mixin[]
|
|
|
|
extends?: Extends
|
|
|
|
emits?: (Emits | EmitNames[]) & ThisType<void>
|
|
|
|
setup?: SetupFunction<
|
|
|
|
Readonly<
|
|
|
|
LooseRequired<
|
|
|
|
Props &
|
|
|
|
UnionToIntersection<ExtractOptionProp<Mixin>> &
|
|
|
|
UnionToIntersection<ExtractOptionProp<Extends>>
|
|
|
|
>
|
|
|
|
>,
|
|
|
|
RawBindings,
|
|
|
|
Emits
|
|
|
|
>
|
|
|
|
|
|
|
|
__defaults?: Defaults
|
2022-06-01 13:55:33 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 02:12:21 +00:00
|
|
|
export type ComponentOptionsMixin = ComponentOptionsBase<
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any
|
|
|
|
>
|
|
|
|
|
2022-06-01 13:55:33 +00:00
|
|
|
export type ExtractComputedReturns<T extends any> = {
|
|
|
|
[key in keyof T]: T[key] extends { get: (...args: any[]) => infer TReturn }
|
|
|
|
? TReturn
|
|
|
|
: T[key] extends (...args: any[]) => infer TReturn
|
|
|
|
? TReturn
|
|
|
|
: never
|
|
|
|
}
|
|
|
|
|
|
|
|
export type ComponentOptionsWithProps<
|
|
|
|
PropsOptions = ComponentPropsOptions,
|
|
|
|
RawBindings = Data,
|
|
|
|
D = Data,
|
|
|
|
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-07-05 02:12:21 +00:00
|
|
|
Props = ExtractPropTypes<PropsOptions>,
|
|
|
|
Defaults = ExtractDefaultPropTypes<PropsOptions>
|
|
|
|
> = ComponentOptionsBase<
|
|
|
|
Props,
|
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C,
|
|
|
|
M,
|
|
|
|
Mixin,
|
|
|
|
Extends,
|
|
|
|
Emits,
|
|
|
|
EmitsNames,
|
|
|
|
Defaults
|
|
|
|
> & {
|
2022-06-01 13:55:33 +00:00
|
|
|
props?: PropsOptions
|
|
|
|
} & ThisType<
|
2022-07-05 02:12:21 +00:00
|
|
|
CreateComponentPublicInstance<
|
|
|
|
Props,
|
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C,
|
|
|
|
M,
|
|
|
|
Mixin,
|
|
|
|
Extends,
|
|
|
|
Emits
|
|
|
|
>
|
2022-06-01 13:55:33 +00:00
|
|
|
>
|
|
|
|
|
|
|
|
export type ComponentOptionsWithArrayProps<
|
|
|
|
PropNames extends string = string,
|
|
|
|
RawBindings = Data,
|
|
|
|
D = Data,
|
|
|
|
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,
|
|
|
|
Props = Readonly<{ [key in PropNames]?: any }>
|
2022-07-05 02:12:21 +00:00
|
|
|
> = ComponentOptionsBase<
|
|
|
|
Props,
|
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C,
|
|
|
|
M,
|
|
|
|
Mixin,
|
|
|
|
Extends,
|
|
|
|
Emits,
|
|
|
|
EmitsNames,
|
|
|
|
{}
|
|
|
|
> & {
|
2022-06-01 13:55:33 +00:00
|
|
|
props?: PropNames[]
|
|
|
|
} & ThisType<
|
2022-07-05 02:12:21 +00:00
|
|
|
CreateComponentPublicInstance<
|
|
|
|
Props,
|
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C,
|
|
|
|
M,
|
|
|
|
Mixin,
|
|
|
|
Extends,
|
|
|
|
Emits
|
|
|
|
>
|
2022-06-01 13:55:33 +00:00
|
|
|
>
|
|
|
|
|
|
|
|
export type ComponentOptionsWithoutProps<
|
|
|
|
Props = {},
|
|
|
|
RawBindings = Data,
|
|
|
|
D = Data,
|
|
|
|
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-07-05 02:12:21 +00:00
|
|
|
> = ComponentOptionsBase<
|
|
|
|
Props,
|
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C,
|
|
|
|
M,
|
|
|
|
Mixin,
|
|
|
|
Extends,
|
|
|
|
Emits,
|
|
|
|
EmitsNames,
|
|
|
|
{}
|
|
|
|
> & {
|
2022-06-01 13:55:33 +00:00
|
|
|
props?: undefined
|
|
|
|
} & ThisType<
|
2022-07-05 02:12:21 +00:00
|
|
|
CreateComponentPublicInstance<
|
|
|
|
Props,
|
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C,
|
|
|
|
M,
|
|
|
|
Mixin,
|
|
|
|
Extends,
|
|
|
|
Emits
|
|
|
|
>
|
2022-06-01 13:55:33 +00:00
|
|
|
>
|
|
|
|
|
|
|
|
export type WithLegacyAPI<T, D, C, M, Props> = T &
|
|
|
|
Omit<Vue2ComponentOptions<Vue, D, M, C, Props>, keyof T>
|