Skip to content

Commit 0df8be2

Browse files
committed
wip
1 parent 1681139 commit 0df8be2

File tree

1 file changed

+78
-44
lines changed

1 file changed

+78
-44
lines changed

packages/runtime-core/src/apiDefineComponent.ts

Lines changed: 78 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ export type PublicProps = VNodeProps &
4949
AllowedComponentProps &
5050
ComponentCustomProps
5151

52+
type ResolveProps<PropsOrPropOptions, E extends EmitsOptions> = Readonly<
53+
PropsOrPropOptions extends ComponentPropsOptions
54+
? ExtractPropTypes<PropsOrPropOptions>
55+
: PropsOrPropOptions
56+
> &
57+
({} extends E ? {} : EmitsToProps<E>)
58+
5259
export type DefineComponent<
5360
OptionsOrPropsOrPropOptions = {},
5461
RawBindings = {},
@@ -57,37 +64,44 @@ export type DefineComponent<
5764
M extends MethodOptions = MethodOptions,
5865
Mixin = {},
5966
Extends = {},
67+
E extends EmitsOptions = {},
68+
_EE extends string = string,
69+
_PP = PublicProps,
70+
_Props = ResolveProps<OptionsOrPropsOrPropOptions, E>,
71+
_Defaults = ExtractDefaultPropTypes<OptionsOrPropsOrPropOptions>,
6072
S extends SlotsType = {},
6173
LC extends Record<string, Component> = {},
6274
Directives extends Record<string, Directive> = {},
6375
Exposed extends string = string,
6476
Provide extends ComponentProvideOptions = ComponentProvideOptions,
6577
TypeRefs extends Record<string, unknown> = {},
6678
TypeEl extends Element = any,
67-
> = OptionsOrPropsOrPropOptions extends { props?: any }
68-
? InferComponentOptions<OptionsOrPropsOrPropOptions>
69-
: InferComponentOptions<{
70-
props?: OptionsOrPropsOrPropOptions extends ComponentPropsOptions
71-
? OptionsOrPropsOrPropOptions
72-
: {}
73-
computed?: C
74-
methods?: M
75-
mixins?: Mixin[]
76-
extends?: Extends
77-
inject?: {}
78-
slots?: S
79-
components?: LC & GlobalComponents
80-
directives?: Directives & GlobalDirectives
81-
expose?: Exposed[]
82-
provide?: Provide
83-
setup?: () => RawBindings
84-
data?: () => D
85-
__typeProps?: OptionsOrPropsOrPropOptions extends ComponentPropsOptions
86-
? unknown
87-
: OptionsOrPropsOrPropOptions
88-
__typeRefs?: TypeRefs
89-
__typeEl?: TypeEl
90-
}>
79+
> = InferComponentOptions<
80+
OptionsOrPropsOrPropOptions extends { props?: any }
81+
? OptionsOrPropsOrPropOptions
82+
: {
83+
props?: OptionsOrPropsOrPropOptions extends ComponentPropsOptions
84+
? OptionsOrPropsOrPropOptions
85+
: {}
86+
computed?: C
87+
methods?: M
88+
mixins?: Mixin[]
89+
extends?: Extends
90+
inject?: {}
91+
slots?: S
92+
components?: LC & GlobalComponents
93+
directives?: Directives & GlobalDirectives
94+
expose?: Exposed[]
95+
provide?: Provide
96+
setup?: () => RawBindings
97+
data?: () => D
98+
__typeProps?: OptionsOrPropsOrPropOptions extends ComponentPropsOptions
99+
? unknown
100+
: OptionsOrPropsOrPropOptions
101+
__typeRefs?: TypeRefs
102+
__typeEl?: TypeEl
103+
}
104+
>
91105

92106
type InferComponentOptions<T> = T &
93107
(T extends {
@@ -370,26 +384,46 @@ export function defineComponent<
370384
$options: typeof options
371385
}
372386
>,
373-
): DefineComponent<{
374-
props?: PropsOptions
375-
emits?: string[] extends RuntimeEmitsOptions ? {} : RuntimeEmitsOptions
376-
components?: LocalComponents & GlobalComponents
377-
directives?: Directives & GlobalDirectives
378-
slots?: Slots
379-
expose?: Exposed[]
380-
computed?: Computed
381-
methods?: Methods
382-
provide?: Provide
383-
inject?: InjectOptions
384-
mixins?: Mixin[]
385-
extends?: Extends
386-
setup?(): SetupBindings
387-
data?(): Data
388-
__typeProps?: TypeProps
389-
__typeEmits?: TypeEmits
390-
__typeRefs?: TypeRefs
391-
__typeEl?: TypeEl
392-
}>
387+
): DefineComponent<
388+
{
389+
props?: PropsOptions
390+
emits?: string[] extends RuntimeEmitsOptions ? {} : RuntimeEmitsOptions
391+
components?: LocalComponents & GlobalComponents
392+
directives?: Directives & GlobalDirectives
393+
slots?: Slots
394+
expose?: Exposed[]
395+
computed?: Computed
396+
methods?: Methods
397+
provide?: Provide
398+
inject?: InjectOptions
399+
mixins?: Mixin[]
400+
extends?: Extends
401+
setup?(): SetupBindings
402+
data?(): Data
403+
__typeProps?: TypeProps
404+
__typeEmits?: TypeEmits
405+
__typeRefs?: TypeRefs
406+
__typeEl?: TypeEl
407+
},
408+
{},
409+
{},
410+
{},
411+
{},
412+
{},
413+
{},
414+
{},
415+
string,
416+
{},
417+
{},
418+
{},
419+
{},
420+
{},
421+
{},
422+
string,
423+
{},
424+
{},
425+
any
426+
>
393427

394428
// implementation, close to no-op
395429
/*! #__NO_SIDE_EFFECTS__ */

0 commit comments

Comments
 (0)