feat(types): define component improvements (#12612)

This commit is contained in:
Evan You 2022-07-05 10:12:21 +08:00 committed by GitHub
parent d45bbeac27
commit fb93c1be77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 1607 additions and 269 deletions

View File

@ -86,7 +86,8 @@ if (typeof Promise !== 'undefined' && isNative(Promise)) {
}
export function nextTick(): Promise<void>
export function nextTick(cb: (...args: any[]) => any, ctx?: object): void
export function nextTick<T>(this: T, cb: (this: T, ...args: any[]) => any): void
export function nextTick<T>(cb: (this: T, ...args: any[]) => any, ctx: T): void
/**
* @internal
*/

6
types/common.d.ts vendored
View File

@ -13,3 +13,9 @@ type Equal<Left, Right> =
(<U>() => U extends Left ? 1 : 0) extends (<U>() => U extends Right ? 1 : 0) ? true : false;
export type HasDefined<T> = Equal<T, unknown> extends true ? false : true
// If the the type T accepts type "any", output type Y, otherwise output type N.
// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N
export type LooseRequired<T> = { [P in string & keyof T]: T[P] }

11
types/index.d.ts vendored
View File

@ -30,7 +30,8 @@ export {
VNode,
VNodeComponentOptions,
VNodeData,
VNodeDirective
VNodeDirective,
ComponentCustomProps
} from './vnode'
export * from './v3-manual-apis'
@ -47,13 +48,15 @@ export {
// v2 already has option with same name and it's for a single computed
ComputedOptions as ComponentComputedOptions,
MethodOptions as ComponentMethodOptions,
ComponentPropsOptions
ComponentPropsOptions,
ComponentCustomOptions
} from './v3-component-options'
export {
ComponentInstance,
ComponentPublicInstance,
ComponentRenderProxy
} from './v3-component-proxy'
CreateComponentPublicInstance,
ComponentCustomProperties
} from './v3-component-public-instance'
export {
// PropType,
// PropOptions,

12
types/jsx.d.ts vendored
View File

@ -1313,7 +1313,12 @@ type NativeElements = {
>
}
import { VNode, VNodeData } from './vnode'
import {
VNode,
VNodeData,
ComponentCustomProps,
AllowedComponentProps
} from './vnode'
declare global {
namespace JSX {
@ -1329,7 +1334,10 @@ declare global {
// @ts-ignore suppress ts:2374 = Duplicate string index signature.
[name: string]: any
}
interface IntrinsicAttributes extends ReservedProps {}
interface IntrinsicAttributes
extends ReservedProps,
AllowedComponentProps,
ComponentCustomProps {}
}
}

8
types/options.d.ts vendored
View File

@ -2,6 +2,7 @@ import { Vue, CreateElement, CombinedVueInstance } from './vue'
import { VNode, VNodeData, VNodeDirective, NormalizedScopedSlot } from './vnode'
import { SetupContext } from './v3-setup-context'
import { DebuggerEvent } from './v3-generated'
import { DefineComponent } from './v3-define-component'
type Constructor = {
new (...args: any[]): any
@ -19,6 +20,7 @@ export type Component<
| typeof Vue
| FunctionalComponentOptions<Props>
| ComponentOptions<never, Data, Methods, Computed, Props, SetupBindings>
| DefineComponent<any, any, any, any, any>
type EsModule<T> = T | { default: T }
@ -174,7 +176,10 @@ export interface ComponentOptions<
el?: Element | string
template?: string
// hack is for functional component type inference, should not be used in user code
render?(createElement: CreateElement, hack: RenderContext<Props>): VNode
render?(
createElement: CreateElement,
hack: RenderContext<Props>
): VNode | null | void
renderError?(createElement: CreateElement, err: Error): VNode
staticRenderFns?: ((createElement: CreateElement) => VNode)[]
@ -198,6 +203,7 @@ export interface ComponentOptions<
[key: string]:
| Component<any, any, any, any>
| AsyncComponent<any, any, any, any>
| DefineComponent<any, any, any, any, any, any, any, any, any, any>
}
transitions?: { [key: string]: object }
filters?: { [key: string]: Function }

File diff suppressed because it is too large Load Diff

View File

@ -2,11 +2,33 @@ import { Vue } from './vue'
import { VNode } from './vnode'
import { ComponentOptions as Vue2ComponentOptions } from './options'
import { EmitsOptions, SetupContext } from './v3-setup-context'
import { Data } from './common'
import { ComponentPropsOptions, ExtractPropTypes } from './v3-component-props'
import { ComponentRenderProxy } from './v3-component-proxy'
import { Data, LooseRequired, UnionToIntersection } from './common'
import {
ComponentPropsOptions,
ExtractDefaultPropTypes,
ExtractPropTypes
} from './v3-component-props'
import { CreateComponentPublicInstance } from './v3-component-public-instance'
export { ComponentPropsOptions } from './v3-component-props'
/**
* Interface for declaring custom options.
*
* @example
* ```ts
* declare module 'vue' {
* interface ComponentCustomOptions {
* beforeRouteUpdate?(
* to: Route,
* from: Route,
* next: () => void
* ): void
* }
* }
* ```
*/
export interface ComponentCustomOptions {}
export type ComputedGetter<T> = (ctx?: any) => T
export type ComputedSetter<T> = (v: T) => void
@ -34,24 +56,76 @@ export type SetupFunction<
ctx: SetupContext<Emits>
) => RawBindings | (() => VNode | null) | void
interface ComponentOptionsBase<
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<
Props,
D = Data,
C extends ComputedOptions = {},
M extends MethodOptions = {}
RawBindings,
D,
C extends ComputedOptions,
M extends MethodOptions,
Mixin extends ComponentOptionsMixin,
Extends extends ComponentOptionsMixin,
Emits extends EmitsOptions,
EmitNames extends string = string,
Defaults = {}
> extends Omit<
Vue2ComponentOptions<Vue, D, M, C, Props>,
'data' | 'computed' | 'method' | 'setup' | 'props'
> {
// allow any custom options
[key: string]: any
'data' | 'computed' | 'methods' | 'setup' | 'props' | 'mixins' | 'extends'
>,
ComponentCustomOptions {
// rewrite options api types
data?: (this: Props & Vue, vm: Props) => D
data?: (
this: CreateComponentPublicInstance<Props, {}, {}, {}, M, Mixin, Extends>,
vm: CreateComponentPublicInstance<Props, {}, {}, {}, M, Mixin, Extends>
) => D
computed?: C
methods?: M
mixins?: Mixin[]
extends?: Extends
emits?: (Emits | EmitNames[]) & ThisType<void>
setup?: SetupFunction<
Readonly<
LooseRequired<
Props &
UnionToIntersection<ExtractOptionProp<Mixin>> &
UnionToIntersection<ExtractOptionProp<Extends>>
>
>,
RawBindings,
Emits
>
__defaults?: Defaults
}
export type ComponentOptionsMixin = ComponentOptionsBase<
any,
any,
any,
any,
any,
any,
any,
any,
any,
any
>
export type ExtractComputedReturns<T extends any> = {
[key in keyof T]: T[key] extends { get: (...args: any[]) => infer TReturn }
? TReturn
@ -66,17 +140,36 @@ export type ComponentOptionsWithProps<
D = Data,
C extends ComputedOptions = {},
M extends MethodOptions = {},
Mixin = {},
Extends = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
Emits extends EmitsOptions = {},
EmitsNames extends string = string,
Props = ExtractPropTypes<PropsOptions>
> = ComponentOptionsBase<Props, D, C, M> & {
Props = ExtractPropTypes<PropsOptions>,
Defaults = ExtractDefaultPropTypes<PropsOptions>
> = ComponentOptionsBase<
Props,
RawBindings,
D,
C,
M,
Mixin,
Extends,
Emits,
EmitsNames,
Defaults
> & {
props?: PropsOptions
emits?: (Emits | EmitsNames[]) & ThisType<void>
setup?: SetupFunction<Props, RawBindings, Emits>
} & ThisType<
ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits>
CreateComponentPublicInstance<
Props,
RawBindings,
D,
C,
M,
Mixin,
Extends,
Emits
>
>
export type ComponentOptionsWithArrayProps<
@ -85,17 +178,35 @@ export type ComponentOptionsWithArrayProps<
D = Data,
C extends ComputedOptions = {},
M extends MethodOptions = {},
Mixin = {},
Extends = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
Emits extends EmitsOptions = {},
EmitsNames extends string = string,
Props = Readonly<{ [key in PropNames]?: any }>
> = ComponentOptionsBase<Props, D, C, M> & {
> = ComponentOptionsBase<
Props,
RawBindings,
D,
C,
M,
Mixin,
Extends,
Emits,
EmitsNames,
{}
> & {
props?: PropNames[]
emits?: (Emits | EmitsNames[]) & ThisType<void>
setup?: SetupFunction<Props, RawBindings, Emits>
} & ThisType<
ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits>
CreateComponentPublicInstance<
Props,
RawBindings,
D,
C,
M,
Mixin,
Extends,
Emits
>
>
export type ComponentOptionsWithoutProps<
@ -104,16 +215,34 @@ export type ComponentOptionsWithoutProps<
D = Data,
C extends ComputedOptions = {},
M extends MethodOptions = {},
Mixin = {},
Extends = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
Emits extends EmitsOptions = {},
EmitsNames extends string = string
> = ComponentOptionsBase<Props, D, C, M> & {
> = ComponentOptionsBase<
Props,
RawBindings,
D,
C,
M,
Mixin,
Extends,
Emits,
EmitsNames,
{}
> & {
props?: undefined
emits?: (Emits | EmitsNames[]) & ThisType<void>
setup?: SetupFunction<Props, RawBindings, Emits>
} & ThisType<
ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits>
CreateComponentPublicInstance<
Props,
RawBindings,
D,
C,
M,
Mixin,
Extends,
Emits
>
>
export type WithLegacyAPI<T, D, C, M, Props> = T &

View File

@ -1,4 +1,4 @@
import { Data } from './common'
import { Data, IfAny } from './common'
export type ComponentPropsOptions<P = Data> =
| ComponentObjectPropsOptions<P>
@ -48,25 +48,24 @@ type ExtractCorrectPropType<T> = T extends Function
? ExtractFunctionPropType<T>
: Exclude<T, Function>
// prettier-ignore
type InferPropType<T> = T extends null
type InferPropType<T> = [T] extends [null]
? any // null & true would fail to infer
: T extends { type: null | true }
: [T] extends [{ type: null | true }]
? any // As TS issue https://github.com/Microsoft/TypeScript/issues/14829 // somehow `ObjectConstructor` when inferred from { (): T } becomes `any` // `BooleanConstructor` when inferred from PropConstructor(with PropMethod) becomes `Boolean`
: T extends ObjectConstructor | { type: ObjectConstructor }
: [T] extends [ObjectConstructor | { type: ObjectConstructor }]
? Record<string, any>
: T extends BooleanConstructor | { type: BooleanConstructor }
: [T] extends [BooleanConstructor | { type: BooleanConstructor }]
? boolean
: T extends DateConstructor | { type: DateConstructor}
: [T] extends [DateConstructor | { type: DateConstructor }]
? Date
: T extends FunctionConstructor
? Function
: T extends Prop<infer V, infer D>
: [T] extends [(infer U)[] | { type: (infer U)[] }]
? U extends DateConstructor
? Date | InferPropType<U>
: InferPropType<U>
: [T] extends [Prop<infer V, infer D>]
? unknown extends V
? D extends null | undefined
? V
: D
: ExtractCorrectPropType<V>
? IfAny<V, V, D>
: V
: T
export type ExtractPropTypes<O> = {

View File

@ -1,189 +0,0 @@
import { ExtractDefaultPropTypes, ExtractPropTypes } from './v3-component-props'
import {
nextTick,
ShallowUnwrapRef,
UnwrapNestedRefs,
WatchOptions,
WatchStopHandle
} from './v3-generated'
import { Data } from './common'
import { Vue, VueConstructor } from './vue'
import { ComponentOptions as Vue2ComponentOptions } from './options'
import {
ComputedOptions,
MethodOptions,
ExtractComputedReturns
} from './v3-component-options'
import {
ComponentRenderEmitFn,
EmitFn,
EmitsOptions,
ObjectEmitsOptions,
Slots
} from './v3-setup-context'
type EmitsToProps<T extends EmitsOptions> = T extends string[]
? {
[K in string & `on${Capitalize<T[number]>}`]?: (...args: any[]) => any
}
: T extends ObjectEmitsOptions
? {
[K in string &
`on${Capitalize<string & keyof T>}`]?: K extends `on${infer C}`
? T[Uncapitalize<C>] extends null
? (...args: any[]) => any
: (
...args: T[Uncapitalize<C>] extends (...args: infer P) => any
? P
: never
) => any
: never
}
: {}
export type ComponentInstance = InstanceType<VueConstructor>
// public properties exposed on the proxy, which is used as the render context
// in templates (as `this` in the render option)
export type ComponentRenderProxy<
P = {}, // props type extracted from props option
B = {}, // raw bindings returned from setup()
D = {}, // return from data()
C extends ComputedOptions = {},
M extends MethodOptions = {},
Mixin = {},
Extends = {},
Emits extends EmitsOptions = {},
PublicProps = P,
Defaults = {},
MakeDefaultsOptional extends boolean = false
> = {
$data: D
$props: Readonly<
MakeDefaultsOptional extends true
? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults>
: P & PublicProps
>
$attrs: Record<string, string>
$emit: ComponentRenderEmitFn<
Emits,
keyof Emits,
ComponentRenderProxy<
P,
B,
D,
C,
M,
Mixin,
Extends,
Emits,
PublicProps,
Defaults,
MakeDefaultsOptional
>
>
} & Readonly<P> &
ShallowUnwrapRef<B> &
D &
M &
ExtractComputedReturns<C> &
Omit<Vue, '$data' | '$props' | '$attrs' | '$emit'>
// for Vetur and TSX support
type VueConstructorProxy<
PropsOptions,
RawBindings,
Data,
Computed extends ComputedOptions,
Methods extends MethodOptions,
Mixin = {},
Extends = {},
Emits extends EmitsOptions = {},
Props = ExtractPropTypes<PropsOptions> &
({} extends Emits ? {} : EmitsToProps<Emits>)
> = Omit<VueConstructor, never> & {
new (...args: any[]): ComponentRenderProxy<
Props,
ShallowUnwrapRef<RawBindings>,
Data,
Computed,
Methods,
Mixin,
Extends,
Emits,
Props,
ExtractDefaultPropTypes<PropsOptions>,
true
>
}
type DefaultData<V> = object | ((this: V) => object)
type DefaultMethods<V> = { [key: string]: (this: V, ...args: any[]) => any }
type DefaultComputed = { [key: string]: any }
export type VueProxy<
PropsOptions,
RawBindings,
Data = DefaultData<Vue>,
Computed extends ComputedOptions = DefaultComputed,
Methods extends MethodOptions = DefaultMethods<Vue>,
Mixin = {},
Extends = {},
Emits extends EmitsOptions = {}
> = Vue2ComponentOptions<
Vue,
ShallowUnwrapRef<RawBindings> & Data,
Methods,
Computed,
PropsOptions,
ExtractPropTypes<PropsOptions>
> &
VueConstructorProxy<
PropsOptions,
RawBindings,
Data,
Computed,
Methods,
Mixin,
Extends,
Emits
>
// 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
> = {
$data: D
$props: 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
} & P &
ShallowUnwrapRef<B> &
UnwrapNestedRefs<D> &
ExtractComputedReturns<C> &
M

230
types/v3-component-public-instance.d.ts vendored Normal file
View File

@ -0,0 +1,230 @@
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
}

View File

@ -1,15 +1,72 @@
import { ComponentPropsOptions } from './v3-component-props'
import { Component } from '..'
import {
ComponentPropsOptions,
ExtractDefaultPropTypes,
ExtractPropTypes
} from './v3-component-props'
import {
MethodOptions,
ComputedOptions,
ComponentOptionsWithoutProps,
ComponentOptionsWithArrayProps,
ComponentOptionsWithProps
ComponentOptionsWithProps,
ComponentOptionsMixin,
ComponentOptionsBase
} from './v3-component-options'
import { VueProxy } from './v3-component-proxy'
import {
ComponentPublicInstanceConstructor,
CreateComponentPublicInstance
} from './v3-component-public-instance'
import { Data, HasDefined } from './common'
import { EmitsOptions } from './v3-setup-context'
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
}
/**
* overload 1: object format with no props
*/
@ -18,8 +75,8 @@ export function defineComponent<
D = Data,
C extends ComputedOptions = {},
M extends MethodOptions = {},
Mixin = {},
Extends = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
Emits extends EmitsOptions = {},
EmitsNames extends string = string
>(
@ -34,7 +91,8 @@ export function defineComponent<
Emits,
EmitsNames
>
): VueProxy<{}, RawBindings, D, C, M, Mixin, Extends, Emits>
): DefineComponent<{}, RawBindings, D, C, M, Mixin, Extends, Emits>
/**
* overload 2: object format with array props declaration
* props inferred as `{ [key in PropNames]?: any }`
@ -47,8 +105,8 @@ export function defineComponent<
D = Data,
C extends ComputedOptions = {},
M extends MethodOptions = {},
Mixin = {},
Extends = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
Emits extends EmitsOptions = {},
EmitsNames extends string = string,
PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
@ -64,7 +122,7 @@ export function defineComponent<
Emits,
EmitsNames
>
): VueProxy<
): DefineComponent<
Readonly<{ [key in PropNames]?: any }>,
RawBindings,
D,
@ -86,8 +144,8 @@ export function defineComponent<
D = Data,
C extends ComputedOptions = {},
M extends MethodOptions = {},
Mixin = {},
Extends = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
Emits extends EmitsOptions = {},
EmitsNames extends string = string,
PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
@ -116,4 +174,4 @@ export function defineComponent<
Emits,
EmitsNames
>
): VueProxy<PropsOptions, RawBindings, D, C, M, Mixin, Extends, Emits>
): DefineComponent<PropsOptions, RawBindings, D, C, M, Mixin, Extends, Emits>

View File

@ -29,12 +29,6 @@ export type EmitFn<
}[Event]
>
export type ComponentRenderEmitFn<
Options = ObjectEmitsOptions,
Event extends keyof Options = keyof Options,
T extends Vue | void = void
> = EmitFn<Options, Event, T>
export interface SetupContext<E extends EmitsOptions = {}> {
attrs: Data
slots: Slots

13
types/vnode.d.ts vendored
View File

@ -1,6 +1,19 @@
import { Vue } from './vue'
import { DirectiveFunction, DirectiveOptions } from './options'
/**
* For extending allowed non-declared props on components in TSX
*/
export interface ComponentCustomProps {}
/**
* Default allowed non-declared props on component in TSX
*/
export interface AllowedComponentProps {
class?: unknown
style?: unknown
}
export type ScopedSlot = (props: any) => ScopedSlotReturnValue
type ScopedSlotReturnValue =
| VNode