Skip to content

Commit fb93c1b

Browse files
authored
feat(types): define component improvements (#12612)
1 parent d45bbea commit fb93c1b

13 files changed

+1606
-268
lines changed

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
*/

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] }

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,

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

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 }

0 commit comments

Comments
 (0)