Skip to content

Commit 11cd53d

Browse files
committed
types: fix defineComponent return type
1 parent 3193816 commit 11cd53d

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

packages/runtime-core/src/apiDefineComponent.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import {
55
ComponentOptionsWithArrayProps,
66
ComponentOptionsWithObjectProps
77
} from './componentOptions'
8-
import { SetupContext, RenderFunction, FunctionalComponent } from './component'
8+
import {
9+
SetupContext,
10+
RenderFunction,
11+
FunctionalComponent,
12+
DefineComponent
13+
} from './component'
914
import { ComponentPublicInstance } from './componentProxy'
1015
import { ExtractPropTypes, ComponentPropsOptions } from './componentProps'
1116
import { EmitsOptions } from './componentEmits'
@@ -59,7 +64,7 @@ export function defineComponent<
5964
E,
6065
VNodeProps & Props
6166
>
62-
} & ComponentOptionsWithoutProps<Props, RawBindings, D, C, M, E, EE>
67+
} & DefineComponent //& ComponentOptionsWithoutProps<Props, RawBindings, D, C, M, E, EE>
6368

6469
// overload 3: object format with array props declaration
6570
// props inferred as { [key in PropNames]?: any }
@@ -85,7 +90,7 @@ export function defineComponent<
8590
): {
8691
// array props technically doesn't place any contraints on props in TSX
8792
new (): ComponentPublicInstance<VNodeProps, RawBindings, D, C, M, E>
88-
} & ComponentOptionsWithArrayProps<PropNames, RawBindings, D, C, M, E, EE>
93+
} & DefineComponent //& ComponentOptionsWithArrayProps<PropNames, RawBindings, D, C, M, E, EE>
8994

9095
// overload 4: object format with object props declaration
9196
// see `ExtractPropTypes` in ./componentProps.ts
@@ -119,7 +124,7 @@ export function defineComponent<
119124
E,
120125
VNodeProps & ExtractPropTypes<PropsOptions, false>
121126
>
122-
} & ComponentOptionsWithObjectProps<PropsOptions, RawBindings, D, C, M, E, EE>
127+
} & DefineComponent //& ComponentOptionsBase<PropsOptions, RawBindings, D, C, M, E, EE>
123128

124129
// implementation, close to no-op
125130
export function defineComponent(options: unknown) {

packages/runtime-core/src/component.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,17 @@ export interface ClassComponent {
7171
__vccOpts: ComponentOptions
7272
}
7373

74-
export type Component = ComponentOptions | FunctionalComponent<any>
74+
// Allow typescript deferenciate DefineComponent from other interfaces
75+
declare const DefineComponentSymbol: unique symbol
76+
export interface DefineComponent {
77+
[DefineComponentSymbol]: true
78+
[key: string]: any
79+
}
80+
81+
export type Component =
82+
| ComponentOptions
83+
| FunctionalComponent<any>
84+
| DefineComponent
7585

7686
// A type used in public APIs where a component type is expected.
7787
// The constructor type is an artificial type returned by defineComponent().

0 commit comments

Comments
 (0)