Skip to content

Commit 8c0aa34

Browse files
committed
wip(types): align defineComponent type inference w/ v3
1 parent caceece commit 8c0aa34

File tree

7 files changed

+1177
-24
lines changed

7 files changed

+1177
-24
lines changed

types/common.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ 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

types/index.d.ts

Lines changed: 2 additions & 1 deletion
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'

types/jsx.d.ts

Lines changed: 10 additions & 2 deletions
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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ export interface ComponentOptions<
174174
el?: Element | string
175175
template?: string
176176
// hack is for functional component type inference, should not be used in user code
177-
render?(createElement: CreateElement, hack: RenderContext<Props>): VNode
177+
render?(
178+
createElement: CreateElement,
179+
hack: RenderContext<Props>
180+
): VNode | null | void
178181
renderError?(createElement: CreateElement, err: Error): VNode
179182
staticRenderFns?: ((createElement: CreateElement) => VNode)[]
180183

0 commit comments

Comments
 (0)