mirror of
https://github.com/vuejs/vue.git
synced 2024-11-22 04:39:46 +00:00
231 lines
5.6 KiB
TypeScript
231 lines
5.6 KiB
TypeScript
import { ExtractDefaultPropTypes, ExtractPropTypes } from './v3-component-props'
|
|
import {
|
|
DebuggerEvent,
|
|
nextTick,
|
|
ShallowUnwrapRef,
|
|
UnwrapNestedRefs,
|
|
WatchOptions,
|
|
WatchStopHandle
|
|
} from './v3-generated'
|
|
import { Data, UnionToIntersection } from './common'
|
|
|
|
import { VueConstructor } from './vue'
|
|
import {
|
|
ComputedOptions,
|
|
MethodOptions,
|
|
ExtractComputedReturns,
|
|
ComponentOptionsMixin,
|
|
ComponentOptionsBase
|
|
} from './v3-component-options'
|
|
import { EmitFn, EmitsOptions, Slots } from './v3-setup-context'
|
|
|
|
/**
|
|
* 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]
|
|
|
|
type IntersectionMixin<T> = IsDefaultMixinComponent<T> extends true
|
|
? OptionTypesType<{}, {}, {}, {}, {}, {}>
|
|
: UnionToIntersection<ExtractMixin<T>>
|
|
|
|
type UnwrapMixinsType<
|
|
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
|
|
>
|
|
> = {
|
|
// $: ComponentInternalInstance
|
|
$data: D
|
|
$props: Readonly<
|
|
MakeDefaultsOptional extends true
|
|
? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults>
|
|
: P & PublicProps
|
|
>
|
|
$attrs: Data
|
|
$refs: Data
|
|
$slots: Slots
|
|
$root: ComponentPublicInstance | null
|
|
$parent: ComponentPublicInstance | null
|
|
$emit: EmitFn<E>
|
|
$el: any
|
|
$options: Options & MergedComponentOptionsOverride
|
|
$forceUpdate: () => void
|
|
$nextTick: typeof nextTick
|
|
$watch(
|
|
source: string | Function,
|
|
cb: Function,
|
|
options?: WatchOptions
|
|
): WatchStopHandle
|
|
} & Readonly<P> &
|
|
ShallowUnwrapRef<B> &
|
|
UnwrapNestedRefs<D> &
|
|
ExtractComputedReturns<C> &
|
|
M &
|
|
ComponentCustomProperties
|
|
|
|
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
|
|
}
|