Skip to content

Commit fb93c1b

Browse files
authoredJul 5, 2022
feat(types): define component improvements (#12612)
1 parent d45bbea commit fb93c1b

13 files changed

+1606
-268
lines changed
 

Diff for: ‎src/core/util/next-tick.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ if (typeof Promise !== 'undefined' && isNative(Promise)) {
8686
}
8787

8888
export function nextTick(): Promise<void>
89-
export function nextTick(cb: (...args: any[]) => any, ctx?: object): void
89+
export function nextTick<T>(this: T, cb: (this: T, ...args: any[]) => any): void
90+
export function nextTick<T>(cb: (this: T, ...args: any[]) => any, ctx: T): void
9091
/**
9192
* @internal
9293
*/

Diff for: ‎types/common.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ type Equal<Left, Right> =
1313
(<U>() => U extends Left ? 1 : 0) extends (<U>() => U extends Right ? 1 : 0) ? true : false;
1414

1515
export type HasDefined<T> = Equal<T, unknown> extends true ? false : true
16+
17+
// If the the type T accepts type "any", output type Y, otherwise output type N.
18+
// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
19+
export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N
20+
21+
export type LooseRequired<T> = { [P in string & keyof T]: T[P] }

Diff for: ‎types/index.d.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export {
3030
VNode,
3131
VNodeComponentOptions,
3232
VNodeData,
33-
VNodeDirective
33+
VNodeDirective,
34+
ComponentCustomProps
3435
} from './vnode'
3536

3637
export * from './v3-manual-apis'
@@ -47,13 +48,15 @@ export {
4748
// v2 already has option with same name and it's for a single computed
4849
ComputedOptions as ComponentComputedOptions,
4950
MethodOptions as ComponentMethodOptions,
50-
ComponentPropsOptions
51+
ComponentPropsOptions,
52+
ComponentCustomOptions
5153
} from './v3-component-options'
5254
export {
5355
ComponentInstance,
5456
ComponentPublicInstance,
55-
ComponentRenderProxy
56-
} from './v3-component-proxy'
57+
CreateComponentPublicInstance,
58+
ComponentCustomProperties
59+
} from './v3-component-public-instance'
5760
export {
5861
// PropType,
5962
// PropOptions,

Diff for: ‎types/jsx.d.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,12 @@ type NativeElements = {
13131313
>
13141314
}
13151315

1316-
import { VNode, VNodeData } from './vnode'
1316+
import {
1317+
VNode,
1318+
VNodeData,
1319+
ComponentCustomProps,
1320+
AllowedComponentProps
1321+
} from './vnode'
13171322

13181323
declare global {
13191324
namespace JSX {
@@ -1329,7 +1334,10 @@ declare global {
13291334
// @ts-ignore suppress ts:2374 = Duplicate string index signature.
13301335
[name: string]: any
13311336
}
1332-
interface IntrinsicAttributes extends ReservedProps {}
1337+
interface IntrinsicAttributes
1338+
extends ReservedProps,
1339+
AllowedComponentProps,
1340+
ComponentCustomProps {}
13331341
}
13341342
}
13351343

Diff for: ‎types/options.d.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Vue, CreateElement, CombinedVueInstance } from './vue'
22
import { VNode, VNodeData, VNodeDirective, NormalizedScopedSlot } from './vnode'
33
import { SetupContext } from './v3-setup-context'
44
import { DebuggerEvent } from './v3-generated'
5+
import { DefineComponent } from './v3-define-component'
56

67
type Constructor = {
78
new (...args: any[]): any
@@ -19,6 +20,7 @@ export type Component<
1920
| typeof Vue
2021
| FunctionalComponentOptions<Props>
2122
| ComponentOptions<never, Data, Methods, Computed, Props, SetupBindings>
23+
| DefineComponent<any, any, any, any, any>
2224

2325
type EsModule<T> = T | { default: T }
2426

@@ -174,7 +176,10 @@ export interface ComponentOptions<
174176
el?: Element | string
175177
template?: string
176178
// hack is for functional component type inference, should not be used in user code
177-
render?(createElement: CreateElement, hack: RenderContext<Props>): VNode
179+
render?(
180+
createElement: CreateElement,
181+
hack: RenderContext<Props>
182+
): VNode | null | void
178183
renderError?(createElement: CreateElement, err: Error): VNode
179184
staticRenderFns?: ((createElement: CreateElement) => VNode)[]
180185

@@ -198,6 +203,7 @@ export interface ComponentOptions<
198203
[key: string]:
199204
| Component<any, any, any, any>
200205
| AsyncComponent<any, any, any, any>
206+
| DefineComponent<any, any, any, any, any, any, any, any, any, any>
201207
}
202208
transitions?: { [key: string]: object }
203209
filters?: { [key: string]: Function }

Diff for: ‎types/test/v3/define-component-test.tsx

+1,080
Large diffs are not rendered by default.

Diff for: ‎types/v3-component-options.d.ts

+162-33
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,33 @@ import { Vue } from './vue'
22
import { VNode } from './vnode'
33
import { ComponentOptions as Vue2ComponentOptions } from './options'
44
import { EmitsOptions, SetupContext } from './v3-setup-context'
5-
import { Data } from './common'
6-
import { ComponentPropsOptions, ExtractPropTypes } from './v3-component-props'
7-
import { ComponentRenderProxy } from './v3-component-proxy'
5+
import { Data, LooseRequired, UnionToIntersection } from './common'
6+
import {
7+
ComponentPropsOptions,
8+
ExtractDefaultPropTypes,
9+
ExtractPropTypes
10+
} from './v3-component-props'
11+
import { CreateComponentPublicInstance } from './v3-component-public-instance'
812
export { ComponentPropsOptions } from './v3-component-props'
913

14+
/**
15+
* Interface for declaring custom options.
16+
*
17+
* @example
18+
* ```ts
19+
* declare module 'vue' {
20+
* interface ComponentCustomOptions {
21+
* beforeRouteUpdate?(
22+
* to: Route,
23+
* from: Route,
24+
* next: () => void
25+
* ): void
26+
* }
27+
* }
28+
* ```
29+
*/
30+
export interface ComponentCustomOptions {}
31+
1032
export type ComputedGetter<T> = (ctx?: any) => T
1133
export type ComputedSetter<T> = (v: T) => void
1234

@@ -34,24 +56,76 @@ export type SetupFunction<
3456
ctx: SetupContext<Emits>
3557
) => RawBindings | (() => VNode | null) | void
3658

37-
interface ComponentOptionsBase<
59+
type ExtractOptionProp<T> = T extends ComponentOptionsBase<
60+
infer P, // Props
61+
any, // RawBindings
62+
any, // D
63+
any, // C
64+
any, // M
65+
any, // Mixin
66+
any, // Extends
67+
any, // EmitsOptions
68+
any // Defaults
69+
>
70+
? unknown extends P
71+
? {}
72+
: P
73+
: {}
74+
75+
export interface ComponentOptionsBase<
3876
Props,
39-
D = Data,
40-
C extends ComputedOptions = {},
41-
M extends MethodOptions = {}
77+
RawBindings,
78+
D,
79+
C extends ComputedOptions,
80+
M extends MethodOptions,
81+
Mixin extends ComponentOptionsMixin,
82+
Extends extends ComponentOptionsMixin,
83+
Emits extends EmitsOptions,
84+
EmitNames extends string = string,
85+
Defaults = {}
4286
> extends Omit<
43-
Vue2ComponentOptions<Vue, D, M, C, Props>,
44-
'data' | 'computed' | 'method' | 'setup' | 'props'
45-
> {
46-
// allow any custom options
47-
[key: string]: any
48-
87+
Vue2ComponentOptions<Vue, D, M, C, Props>,
88+
'data' | 'computed' | 'methods' | 'setup' | 'props' | 'mixins' | 'extends'
89+
>,
90+
ComponentCustomOptions {
4991
// rewrite options api types
50-
data?: (this: Props & Vue, vm: Props) => D
92+
data?: (
93+
this: CreateComponentPublicInstance<Props, {}, {}, {}, M, Mixin, Extends>,
94+
vm: CreateComponentPublicInstance<Props, {}, {}, {}, M, Mixin, Extends>
95+
) => D
5196
computed?: C
5297
methods?: M
98+
mixins?: Mixin[]
99+
extends?: Extends
100+
emits?: (Emits | EmitNames[]) & ThisType<void>
101+
setup?: SetupFunction<
102+
Readonly<
103+
LooseRequired<
104+
Props &
105+
UnionToIntersection<ExtractOptionProp<Mixin>> &
106+
UnionToIntersection<ExtractOptionProp<Extends>>
107+
>
108+
>,
109+
RawBindings,
110+
Emits
111+
>
112+
113+
__defaults?: Defaults
53114
}
54115

116+
export type ComponentOptionsMixin = ComponentOptionsBase<
117+
any,
118+
any,
119+
any,
120+
any,
121+
any,
122+
any,
123+
any,
124+
any,
125+
any,
126+
any
127+
>
128+
55129
export type ExtractComputedReturns<T extends any> = {
56130
[key in keyof T]: T[key] extends { get: (...args: any[]) => infer TReturn }
57131
? TReturn
@@ -66,17 +140,36 @@ export type ComponentOptionsWithProps<
66140
D = Data,
67141
C extends ComputedOptions = {},
68142
M extends MethodOptions = {},
69-
Mixin = {},
70-
Extends = {},
143+
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
144+
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
71145
Emits extends EmitsOptions = {},
72146
EmitsNames extends string = string,
73-
Props = ExtractPropTypes<PropsOptions>
74-
> = ComponentOptionsBase<Props, D, C, M> & {
147+
Props = ExtractPropTypes<PropsOptions>,
148+
Defaults = ExtractDefaultPropTypes<PropsOptions>
149+
> = ComponentOptionsBase<
150+
Props,
151+
RawBindings,
152+
D,
153+
C,
154+
M,
155+
Mixin,
156+
Extends,
157+
Emits,
158+
EmitsNames,
159+
Defaults
160+
> & {
75161
props?: PropsOptions
76-
emits?: (Emits | EmitsNames[]) & ThisType<void>
77-
setup?: SetupFunction<Props, RawBindings, Emits>
78162
} & ThisType<
79-
ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits>
163+
CreateComponentPublicInstance<
164+
Props,
165+
RawBindings,
166+
D,
167+
C,
168+
M,
169+
Mixin,
170+
Extends,
171+
Emits
172+
>
80173
>
81174

82175
export type ComponentOptionsWithArrayProps<
@@ -85,17 +178,35 @@ export type ComponentOptionsWithArrayProps<
85178
D = Data,
86179
C extends ComputedOptions = {},
87180
M extends MethodOptions = {},
88-
Mixin = {},
89-
Extends = {},
181+
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
182+
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
90183
Emits extends EmitsOptions = {},
91184
EmitsNames extends string = string,
92185
Props = Readonly<{ [key in PropNames]?: any }>
93-
> = ComponentOptionsBase<Props, D, C, M> & {
186+
> = ComponentOptionsBase<
187+
Props,
188+
RawBindings,
189+
D,
190+
C,
191+
M,
192+
Mixin,
193+
Extends,
194+
Emits,
195+
EmitsNames,
196+
{}
197+
> & {
94198
props?: PropNames[]
95-
emits?: (Emits | EmitsNames[]) & ThisType<void>
96-
setup?: SetupFunction<Props, RawBindings, Emits>
97199
} & ThisType<
98-
ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits>
200+
CreateComponentPublicInstance<
201+
Props,
202+
RawBindings,
203+
D,
204+
C,
205+
M,
206+
Mixin,
207+
Extends,
208+
Emits
209+
>
99210
>
100211

101212
export type ComponentOptionsWithoutProps<
@@ -104,16 +215,34 @@ export type ComponentOptionsWithoutProps<
104215
D = Data,
105216
C extends ComputedOptions = {},
106217
M extends MethodOptions = {},
107-
Mixin = {},
108-
Extends = {},
218+
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
219+
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
109220
Emits extends EmitsOptions = {},
110221
EmitsNames extends string = string
111-
> = ComponentOptionsBase<Props, D, C, M> & {
222+
> = ComponentOptionsBase<
223+
Props,
224+
RawBindings,
225+
D,
226+
C,
227+
M,
228+
Mixin,
229+
Extends,
230+
Emits,
231+
EmitsNames,
232+
{}
233+
> & {
112234
props?: undefined
113-
emits?: (Emits | EmitsNames[]) & ThisType<void>
114-
setup?: SetupFunction<Props, RawBindings, Emits>
115235
} & ThisType<
116-
ComponentRenderProxy<Props, RawBindings, D, C, M, Mixin, Extends, Emits>
236+
CreateComponentPublicInstance<
237+
Props,
238+
RawBindings,
239+
D,
240+
C,
241+
M,
242+
Mixin,
243+
Extends,
244+
Emits
245+
>
117246
>
118247

119248
export type WithLegacyAPI<T, D, C, M, Props> = T &

Diff for: ‎types/v3-component-props.d.ts

+19-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Data } from './common'
1+
import { Data, IfAny } from './common'
22

33
export type ComponentPropsOptions<P = Data> =
44
| ComponentObjectPropsOptions<P>
@@ -48,26 +48,25 @@ type ExtractCorrectPropType<T> = T extends Function
4848
? ExtractFunctionPropType<T>
4949
: Exclude<T, Function>
5050

51-
// prettier-ignore
52-
type InferPropType<T> = T extends null
51+
type InferPropType<T> = [T] extends [null]
5352
? any // null & true would fail to infer
54-
: T extends { type: null | true }
55-
? 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`
56-
: T extends ObjectConstructor | { type: ObjectConstructor }
57-
? Record<string, any>
58-
: T extends BooleanConstructor | { type: BooleanConstructor }
59-
? boolean
60-
: T extends DateConstructor | { type: DateConstructor}
61-
? Date
62-
: T extends FunctionConstructor
63-
? Function
64-
: T extends Prop<infer V, infer D>
65-
? unknown extends V
66-
? D extends null | undefined
67-
? V
68-
: D
69-
: ExtractCorrectPropType<V>
70-
: T
53+
: [T] extends [{ type: null | true }]
54+
? 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`
55+
: [T] extends [ObjectConstructor | { type: ObjectConstructor }]
56+
? Record<string, any>
57+
: [T] extends [BooleanConstructor | { type: BooleanConstructor }]
58+
? boolean
59+
: [T] extends [DateConstructor | { type: DateConstructor }]
60+
? Date
61+
: [T] extends [(infer U)[] | { type: (infer U)[] }]
62+
? U extends DateConstructor
63+
? Date | InferPropType<U>
64+
: InferPropType<U>
65+
: [T] extends [Prop<infer V, infer D>]
66+
? unknown extends V
67+
? IfAny<V, V, D>
68+
: V
69+
: T
7170

7271
export type ExtractPropTypes<O> = {
7372
// use `keyof Pick<O, RequiredKeys<O>>` instead of `RequiredKeys<O>` to support IDE features

Diff for: ‎types/v3-component-proxy.d.ts

-189
This file was deleted.

Diff for: ‎types/v3-component-public-instance.d.ts

+230
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
import { ExtractDefaultPropTypes, ExtractPropTypes } from './v3-component-props'
2+
import {
3+
DebuggerEvent,
4+
nextTick,
5+
ShallowUnwrapRef,
6+
UnwrapNestedRefs,
7+
WatchOptions,
8+
WatchStopHandle
9+
} from './v3-generated'
10+
import { Data, UnionToIntersection } from './common'
11+
12+
import { VueConstructor } from './vue'
13+
import {
14+
ComputedOptions,
15+
MethodOptions,
16+
ExtractComputedReturns,
17+
ComponentOptionsMixin,
18+
ComponentOptionsBase
19+
} from './v3-component-options'
20+
import { EmitFn, EmitsOptions, Slots } from './v3-setup-context'
21+
22+
/**
23+
* Custom properties added to component instances in any way and can be accessed through `this`
24+
*
25+
* @example
26+
* ```ts
27+
* import { Router } from 'vue-router'
28+
*
29+
* declare module 'vue' {
30+
* interface ComponentCustomProperties {
31+
* $router: Router
32+
* }
33+
* }
34+
* ```
35+
*/
36+
export interface ComponentCustomProperties {}
37+
38+
export type ComponentInstance = InstanceType<VueConstructor>
39+
40+
export type OptionTypesKeys = 'P' | 'B' | 'D' | 'C' | 'M' | 'Defaults'
41+
42+
export type OptionTypesType<
43+
P = {},
44+
B = {},
45+
D = {},
46+
C extends ComputedOptions = {},
47+
M extends MethodOptions = {},
48+
Defaults = {}
49+
> = {
50+
P: P
51+
B: B
52+
D: D
53+
C: C
54+
M: M
55+
Defaults: Defaults
56+
}
57+
58+
type IsDefaultMixinComponent<T> = T extends ComponentOptionsMixin
59+
? ComponentOptionsMixin extends T
60+
? true
61+
: false
62+
: false
63+
64+
type MixinToOptionTypes<T> = T extends ComponentOptionsBase<
65+
infer P,
66+
infer B,
67+
infer D,
68+
infer C,
69+
infer M,
70+
infer Mixin,
71+
infer Extends,
72+
any,
73+
any,
74+
infer Defaults
75+
>
76+
? OptionTypesType<P & {}, B & {}, D & {}, C & {}, M & {}, Defaults & {}> &
77+
IntersectionMixin<Mixin> &
78+
IntersectionMixin<Extends>
79+
: never
80+
81+
// ExtractMixin(map type) is used to resolve circularly references
82+
type ExtractMixin<T> = {
83+
Mixin: MixinToOptionTypes<T>
84+
}[T extends ComponentOptionsMixin ? 'Mixin' : never]
85+
86+
type IntersectionMixin<T> = IsDefaultMixinComponent<T> extends true
87+
? OptionTypesType<{}, {}, {}, {}, {}, {}>
88+
: UnionToIntersection<ExtractMixin<T>>
89+
90+
type UnwrapMixinsType<
91+
T,
92+
Type extends OptionTypesKeys
93+
> = T extends OptionTypesType ? T[Type] : never
94+
95+
type EnsureNonVoid<T> = T extends void ? {} : T
96+
97+
export type CreateComponentPublicInstance<
98+
P = {},
99+
B = {},
100+
D = {},
101+
C extends ComputedOptions = {},
102+
M extends MethodOptions = {},
103+
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
104+
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
105+
E extends EmitsOptions = {},
106+
PublicProps = P,
107+
Defaults = {},
108+
MakeDefaultsOptional extends boolean = false,
109+
PublicMixin = IntersectionMixin<Mixin> & IntersectionMixin<Extends>,
110+
PublicP = UnwrapMixinsType<PublicMixin, 'P'> & EnsureNonVoid<P>,
111+
PublicB = UnwrapMixinsType<PublicMixin, 'B'> & EnsureNonVoid<B>,
112+
PublicD = UnwrapMixinsType<PublicMixin, 'D'> & EnsureNonVoid<D>,
113+
PublicC extends ComputedOptions = UnwrapMixinsType<PublicMixin, 'C'> &
114+
EnsureNonVoid<C>,
115+
PublicM extends MethodOptions = UnwrapMixinsType<PublicMixin, 'M'> &
116+
EnsureNonVoid<M>,
117+
PublicDefaults = UnwrapMixinsType<PublicMixin, 'Defaults'> &
118+
EnsureNonVoid<Defaults>
119+
> = ComponentPublicInstance<
120+
PublicP,
121+
PublicB,
122+
PublicD,
123+
PublicC,
124+
PublicM,
125+
E,
126+
PublicProps,
127+
PublicDefaults,
128+
MakeDefaultsOptional
129+
>
130+
131+
// public properties exposed on the proxy, which is used as the render context
132+
// in templates (as `this` in the render option)
133+
export type ComponentPublicInstance<
134+
P = {}, // props type extracted from props option
135+
B = {}, // raw bindings returned from setup()
136+
D = {}, // return from data()
137+
C extends ComputedOptions = {},
138+
M extends MethodOptions = {},
139+
E extends EmitsOptions = {},
140+
PublicProps = P,
141+
Defaults = {},
142+
MakeDefaultsOptional extends boolean = false,
143+
Options = ComponentOptionsBase<
144+
any,
145+
any,
146+
any,
147+
any,
148+
any,
149+
any,
150+
any,
151+
any,
152+
any,
153+
any
154+
>
155+
> = {
156+
// $: ComponentInternalInstance
157+
$data: D
158+
$props: Readonly<
159+
MakeDefaultsOptional extends true
160+
? Partial<Defaults> & Omit<P & PublicProps, keyof Defaults>
161+
: P & PublicProps
162+
>
163+
$attrs: Data
164+
$refs: Data
165+
$slots: Slots
166+
$root: ComponentPublicInstance | null
167+
$parent: ComponentPublicInstance | null
168+
$emit: EmitFn<E>
169+
$el: any
170+
$options: Options & MergedComponentOptionsOverride
171+
$forceUpdate: () => void
172+
$nextTick: typeof nextTick
173+
$watch(
174+
source: string | Function,
175+
cb: Function,
176+
options?: WatchOptions
177+
): WatchStopHandle
178+
} & Readonly<P> &
179+
ShallowUnwrapRef<B> &
180+
UnwrapNestedRefs<D> &
181+
ExtractComputedReturns<C> &
182+
M &
183+
ComponentCustomProperties
184+
185+
type MergedHook<T = () => void> = T | T[]
186+
187+
export type MergedComponentOptionsOverride = {
188+
beforeCreate?: MergedHook
189+
created?: MergedHook
190+
beforeMount?: MergedHook
191+
mounted?: MergedHook
192+
beforeUpdate?: MergedHook
193+
updated?: MergedHook
194+
activated?: MergedHook
195+
deactivated?: MergedHook
196+
/** @deprecated use `beforeUnmount` instead */
197+
beforeDestroy?: MergedHook
198+
beforeUnmount?: MergedHook
199+
/** @deprecated use `unmounted` instead */
200+
destroyed?: MergedHook
201+
unmounted?: MergedHook
202+
renderTracked?: MergedHook<DebuggerHook>
203+
renderTriggered?: MergedHook<DebuggerHook>
204+
errorCaptured?: MergedHook<ErrorCapturedHook>
205+
}
206+
207+
export type DebuggerHook = (e: DebuggerEvent) => void
208+
209+
export type ErrorCapturedHook<TError = unknown> = (
210+
err: TError,
211+
instance: ComponentPublicInstance | null,
212+
info: string
213+
) => boolean | void
214+
215+
export type ComponentPublicInstanceConstructor<
216+
T extends ComponentPublicInstance<
217+
Props,
218+
RawBindings,
219+
D,
220+
C,
221+
M
222+
> = ComponentPublicInstance<any, any, any>,
223+
Props = any,
224+
RawBindings = any,
225+
D = any,
226+
C extends ComputedOptions = ComputedOptions,
227+
M extends MethodOptions = MethodOptions
228+
> = {
229+
new (...args: any[]): T
230+
}

Diff for: ‎types/v3-define-component.d.ts

+70-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,72 @@
1-
import { ComponentPropsOptions } from './v3-component-props'
1+
import { Component } from '..'
2+
import {
3+
ComponentPropsOptions,
4+
ExtractDefaultPropTypes,
5+
ExtractPropTypes
6+
} from './v3-component-props'
27
import {
38
MethodOptions,
49
ComputedOptions,
510
ComponentOptionsWithoutProps,
611
ComponentOptionsWithArrayProps,
7-
ComponentOptionsWithProps
12+
ComponentOptionsWithProps,
13+
ComponentOptionsMixin,
14+
ComponentOptionsBase
815
} from './v3-component-options'
9-
import { VueProxy } from './v3-component-proxy'
16+
import {
17+
ComponentPublicInstanceConstructor,
18+
CreateComponentPublicInstance
19+
} from './v3-component-public-instance'
1020
import { Data, HasDefined } from './common'
1121
import { EmitsOptions } from './v3-setup-context'
1222

23+
type DefineComponent<
24+
PropsOrPropOptions = {},
25+
RawBindings = {},
26+
D = {},
27+
C extends ComputedOptions = ComputedOptions,
28+
M extends MethodOptions = MethodOptions,
29+
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
30+
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
31+
E extends EmitsOptions = {},
32+
EE extends string = string,
33+
Props = Readonly<
34+
PropsOrPropOptions extends ComponentPropsOptions
35+
? ExtractPropTypes<PropsOrPropOptions>
36+
: PropsOrPropOptions
37+
>,
38+
Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>
39+
> = ComponentPublicInstanceConstructor<
40+
CreateComponentPublicInstance<
41+
Props,
42+
RawBindings,
43+
D,
44+
C,
45+
M,
46+
Mixin,
47+
Extends,
48+
E,
49+
Props,
50+
Defaults,
51+
true
52+
> &
53+
Props
54+
> &
55+
ComponentOptionsBase<
56+
Props,
57+
RawBindings,
58+
D,
59+
C,
60+
M,
61+
Mixin,
62+
Extends,
63+
E,
64+
EE,
65+
Defaults
66+
> & {
67+
props: PropsOrPropOptions
68+
}
69+
1370
/**
1471
* overload 1: object format with no props
1572
*/
@@ -18,8 +75,8 @@ export function defineComponent<
1875
D = Data,
1976
C extends ComputedOptions = {},
2077
M extends MethodOptions = {},
21-
Mixin = {},
22-
Extends = {},
78+
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
79+
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
2380
Emits extends EmitsOptions = {},
2481
EmitsNames extends string = string
2582
>(
@@ -34,7 +91,8 @@ export function defineComponent<
3491
Emits,
3592
EmitsNames
3693
>
37-
): VueProxy<{}, RawBindings, D, C, M, Mixin, Extends, Emits>
94+
): DefineComponent<{}, RawBindings, D, C, M, Mixin, Extends, Emits>
95+
3896
/**
3997
* overload 2: object format with array props declaration
4098
* props inferred as `{ [key in PropNames]?: any }`
@@ -47,8 +105,8 @@ export function defineComponent<
47105
D = Data,
48106
C extends ComputedOptions = {},
49107
M extends MethodOptions = {},
50-
Mixin = {},
51-
Extends = {},
108+
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
109+
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
52110
Emits extends EmitsOptions = {},
53111
EmitsNames extends string = string,
54112
PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
@@ -64,7 +122,7 @@ export function defineComponent<
64122
Emits,
65123
EmitsNames
66124
>
67-
): VueProxy<
125+
): DefineComponent<
68126
Readonly<{ [key in PropNames]?: any }>,
69127
RawBindings,
70128
D,
@@ -86,8 +144,8 @@ export function defineComponent<
86144
D = Data,
87145
C extends ComputedOptions = {},
88146
M extends MethodOptions = {},
89-
Mixin = {},
90-
Extends = {},
147+
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
148+
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
91149
Emits extends EmitsOptions = {},
92150
EmitsNames extends string = string,
93151
PropsOptions extends ComponentPropsOptions = ComponentPropsOptions
@@ -116,4 +174,4 @@ export function defineComponent<
116174
Emits,
117175
EmitsNames
118176
>
119-
): VueProxy<PropsOptions, RawBindings, D, C, M, Mixin, Extends, Emits>
177+
): DefineComponent<PropsOptions, RawBindings, D, C, M, Mixin, Extends, Emits>

Diff for: ‎types/v3-setup-context.d.ts

-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ export type EmitFn<
2929
}[Event]
3030
>
3131

32-
export type ComponentRenderEmitFn<
33-
Options = ObjectEmitsOptions,
34-
Event extends keyof Options = keyof Options,
35-
T extends Vue | void = void
36-
> = EmitFn<Options, Event, T>
37-
3832
export interface SetupContext<E extends EmitsOptions = {}> {
3933
attrs: Data
4034
slots: Slots

Diff for: ‎types/vnode.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import { Vue } from './vue'
22
import { DirectiveFunction, DirectiveOptions } from './options'
33

4+
/**
5+
* For extending allowed non-declared props on components in TSX
6+
*/
7+
export interface ComponentCustomProps {}
8+
9+
/**
10+
* Default allowed non-declared props on component in TSX
11+
*/
12+
export interface AllowedComponentProps {
13+
class?: unknown
14+
style?: unknown
15+
}
16+
417
export type ScopedSlot = (props: any) => ScopedSlotReturnValue
518
type ScopedSlotReturnValue =
619
| VNode

0 commit comments

Comments
 (0)
Please sign in to comment.