2022-07-05 02:12:21 +00:00
|
|
|
import {
|
|
|
|
DebuggerEvent,
|
|
|
|
ShallowUnwrapRef,
|
2022-07-08 07:39:16 +00:00
|
|
|
UnwrapNestedRefs
|
2022-07-05 02:12:21 +00:00
|
|
|
} from './v3-generated'
|
2022-07-08 07:39:16 +00:00
|
|
|
import { UnionToIntersection } from './common'
|
2022-07-05 02:12:21 +00:00
|
|
|
|
2022-07-13 02:44:57 +00:00
|
|
|
import { Vue, VueConstructor } from './vue'
|
2022-07-05 02:12:21 +00:00
|
|
|
import {
|
|
|
|
ComputedOptions,
|
|
|
|
MethodOptions,
|
|
|
|
ExtractComputedReturns,
|
|
|
|
ComponentOptionsMixin,
|
|
|
|
ComponentOptionsBase
|
|
|
|
} from './v3-component-options'
|
2022-07-13 02:44:57 +00:00
|
|
|
import { EmitFn, EmitsOptions } from './v3-setup-context'
|
2022-07-05 02:12:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom properties added to component instances in any way and can be accessed through `this`
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```ts
|
|
|
|
* import { Router } from 'vue-router'
|
|
|
|
*
|
|
|
|
* declare module 'vue' {
|
|
|
|
* interface ComponentCustomProperties {
|
|
|
|
* $router: Router
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
export interface ComponentCustomProperties {}
|
|
|
|
|
|
|
|
export type ComponentInstance = InstanceType<VueConstructor>
|
|
|
|
|
|
|
|
export type OptionTypesKeys = 'P' | 'B' | 'D' | 'C' | 'M' | 'Defaults'
|
|
|
|
|
|
|
|
export type OptionTypesType<
|
|
|
|
P = {},
|
|
|
|
B = {},
|
|
|
|
D = {},
|
|
|
|
C extends ComputedOptions = {},
|
|
|
|
M extends MethodOptions = {},
|
|
|
|
Defaults = {}
|
|
|
|
> = {
|
|
|
|
P: P
|
|
|
|
B: B
|
|
|
|
D: D
|
|
|
|
C: C
|
|
|
|
M: M
|
|
|
|
Defaults: Defaults
|
|
|
|
}
|
|
|
|
|
|
|
|
type IsDefaultMixinComponent<T> = T extends ComponentOptionsMixin
|
|
|
|
? ComponentOptionsMixin extends T
|
|
|
|
? true
|
|
|
|
: false
|
|
|
|
: false
|
|
|
|
|
|
|
|
type MixinToOptionTypes<T> = T extends ComponentOptionsBase<
|
|
|
|
infer P,
|
|
|
|
infer B,
|
|
|
|
infer D,
|
|
|
|
infer C,
|
|
|
|
infer M,
|
|
|
|
infer Mixin,
|
|
|
|
infer Extends,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
infer Defaults
|
|
|
|
>
|
|
|
|
? OptionTypesType<P & {}, B & {}, D & {}, C & {}, M & {}, Defaults & {}> &
|
|
|
|
IntersectionMixin<Mixin> &
|
|
|
|
IntersectionMixin<Extends>
|
|
|
|
: never
|
|
|
|
|
|
|
|
// ExtractMixin(map type) is used to resolve circularly references
|
|
|
|
type ExtractMixin<T> = {
|
|
|
|
Mixin: MixinToOptionTypes<T>
|
|
|
|
}[T extends ComponentOptionsMixin ? 'Mixin' : never]
|
|
|
|
|
2022-08-18 07:56:37 +00:00
|
|
|
export type IntersectionMixin<T> = IsDefaultMixinComponent<T> extends true
|
2022-07-05 02:12:21 +00:00
|
|
|
? OptionTypesType<{}, {}, {}, {}, {}, {}>
|
|
|
|
: UnionToIntersection<ExtractMixin<T>>
|
|
|
|
|
2022-08-18 07:56:37 +00:00
|
|
|
export type UnwrapMixinsType<
|
2022-07-05 02:12:21 +00:00
|
|
|
T,
|
|
|
|
Type extends OptionTypesKeys
|
|
|
|
> = T extends OptionTypesType ? T[Type] : never
|
|
|
|
|
|
|
|
type EnsureNonVoid<T> = T extends void ? {} : T
|
|
|
|
|
|
|
|
export type CreateComponentPublicInstance<
|
|
|
|
P = {},
|
|
|
|
B = {},
|
|
|
|
D = {},
|
|
|
|
C extends ComputedOptions = {},
|
|
|
|
M extends MethodOptions = {},
|
|
|
|
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
|
|
|
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
|
|
|
E extends EmitsOptions = {},
|
|
|
|
PublicProps = P,
|
|
|
|
Defaults = {},
|
|
|
|
MakeDefaultsOptional extends boolean = false,
|
|
|
|
PublicMixin = IntersectionMixin<Mixin> & IntersectionMixin<Extends>,
|
|
|
|
PublicP = UnwrapMixinsType<PublicMixin, 'P'> & EnsureNonVoid<P>,
|
|
|
|
PublicB = UnwrapMixinsType<PublicMixin, 'B'> & EnsureNonVoid<B>,
|
|
|
|
PublicD = UnwrapMixinsType<PublicMixin, 'D'> & EnsureNonVoid<D>,
|
|
|
|
PublicC extends ComputedOptions = UnwrapMixinsType<PublicMixin, 'C'> &
|
|
|
|
EnsureNonVoid<C>,
|
|
|
|
PublicM extends MethodOptions = UnwrapMixinsType<PublicMixin, 'M'> &
|
|
|
|
EnsureNonVoid<M>,
|
|
|
|
PublicDefaults = UnwrapMixinsType<PublicMixin, 'Defaults'> &
|
|
|
|
EnsureNonVoid<Defaults>
|
|
|
|
> = ComponentPublicInstance<
|
|
|
|
PublicP,
|
|
|
|
PublicB,
|
|
|
|
PublicD,
|
|
|
|
PublicC,
|
|
|
|
PublicM,
|
|
|
|
E,
|
|
|
|
PublicProps,
|
|
|
|
PublicDefaults,
|
|
|
|
MakeDefaultsOptional
|
|
|
|
>
|
|
|
|
|
|
|
|
// public properties exposed on the proxy, which is used as the render context
|
|
|
|
// in templates (as `this` in the render option)
|
|
|
|
export type ComponentPublicInstance<
|
|
|
|
P = {}, // props type extracted from props option
|
|
|
|
B = {}, // raw bindings returned from setup()
|
|
|
|
D = {}, // return from data()
|
|
|
|
C extends ComputedOptions = {},
|
|
|
|
M extends MethodOptions = {},
|
|
|
|
E extends EmitsOptions = {},
|
|
|
|
PublicProps = P,
|
|
|
|
Defaults = {},
|
|
|
|
MakeDefaultsOptional extends boolean = false,
|
|
|
|
Options = ComponentOptionsBase<
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any,
|
|
|
|
any
|
|
|
|
>
|
2022-07-08 07:39:16 +00:00
|
|
|
> = Vue3Instance<
|
|
|
|
D,
|
|
|
|
P,
|
|
|
|
PublicProps,
|
|
|
|
E,
|
|
|
|
Defaults,
|
|
|
|
MakeDefaultsOptional,
|
|
|
|
Options
|
|
|
|
> &
|
|
|
|
Readonly<P> &
|
2022-07-05 02:12:21 +00:00
|
|
|
ShallowUnwrapRef<B> &
|
|
|
|
UnwrapNestedRefs<D> &
|
|
|
|
ExtractComputedReturns<C> &
|
|
|
|
M &
|
|
|
|
ComponentCustomProperties
|
|
|
|
|
2022-07-08 07:39:16 +00:00
|
|
|
interface Vue3Instance<
|
|
|
|
D,
|
|
|
|
P,
|
|
|
|
PublicProps,
|
|
|
|
E,
|
|
|
|
Defaults,
|
|
|
|
MakeDefaultsOptional,
|
|
|
|
Options
|
2022-07-13 02:44:57 +00:00
|
|
|
> extends Vue<
|
|
|
|
D,
|
|
|
|
Readonly<
|
|
|
|
MakeDefaultsOptional extends true
|
|
|
|
? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults>
|
|
|
|
: P & PublicProps
|
|
|
|
>,
|
|
|
|
ComponentPublicInstance,
|
|
|
|
Options & MergedComponentOptionsOverride,
|
|
|
|
EmitFn<E>
|
|
|
|
> {}
|
2022-07-08 07:39:16 +00:00
|
|
|
|
2022-07-05 02:12:21 +00:00
|
|
|
type MergedHook<T = () => void> = T | T[]
|
|
|
|
|
|
|
|
export type MergedComponentOptionsOverride = {
|
|
|
|
beforeCreate?: MergedHook
|
|
|
|
created?: MergedHook
|
|
|
|
beforeMount?: MergedHook
|
|
|
|
mounted?: MergedHook
|
|
|
|
beforeUpdate?: MergedHook
|
|
|
|
updated?: MergedHook
|
|
|
|
activated?: MergedHook
|
|
|
|
deactivated?: MergedHook
|
|
|
|
/** @deprecated use `beforeUnmount` instead */
|
|
|
|
beforeDestroy?: MergedHook
|
|
|
|
beforeUnmount?: MergedHook
|
|
|
|
/** @deprecated use `unmounted` instead */
|
|
|
|
destroyed?: MergedHook
|
|
|
|
unmounted?: MergedHook
|
|
|
|
renderTracked?: MergedHook<DebuggerHook>
|
|
|
|
renderTriggered?: MergedHook<DebuggerHook>
|
|
|
|
errorCaptured?: MergedHook<ErrorCapturedHook>
|
|
|
|
}
|
|
|
|
|
|
|
|
export type DebuggerHook = (e: DebuggerEvent) => void
|
|
|
|
|
|
|
|
export type ErrorCapturedHook<TError = unknown> = (
|
|
|
|
err: TError,
|
|
|
|
instance: ComponentPublicInstance | null,
|
|
|
|
info: string
|
|
|
|
) => boolean | void
|
|
|
|
|
|
|
|
export type ComponentPublicInstanceConstructor<
|
|
|
|
T extends ComponentPublicInstance<
|
|
|
|
Props,
|
|
|
|
RawBindings,
|
|
|
|
D,
|
|
|
|
C,
|
|
|
|
M
|
|
|
|
> = ComponentPublicInstance<any, any, any>,
|
|
|
|
Props = any,
|
|
|
|
RawBindings = any,
|
|
|
|
D = any,
|
|
|
|
C extends ComputedOptions = ComputedOptions,
|
|
|
|
M extends MethodOptions = MethodOptions
|
|
|
|
> = {
|
|
|
|
new (...args: any[]): T
|
|
|
|
}
|