Skip to content

Commit 3eb9224

Browse files
committed
wip(types): fix type defaults
1 parent 82a4805 commit 3eb9224

File tree

4 files changed

+52
-14
lines changed

4 files changed

+52
-14
lines changed

types/options.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type Component<
2020
| typeof Vue
2121
| FunctionalComponentOptions<Props>
2222
| ComponentOptions<never, Data, Methods, Computed, Props, SetupBindings>
23+
| DefineComponent<any, any, any, any, any>
2324

2425
type EsModule<T> = T | { default: T }
2526

types/v3-component-options.d.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { VNode } from './vnode'
33
import { ComponentOptions as Vue2ComponentOptions } from './options'
44
import { EmitsOptions, SetupContext } from './v3-setup-context'
55
import { Data, LooseRequired, UnionToIntersection } from './common'
6-
import { ComponentPropsOptions, ExtractPropTypes } from './v3-component-props'
6+
import {
7+
ComponentPropsOptions,
8+
ExtractDefaultPropTypes,
9+
ExtractPropTypes
10+
} from './v3-component-props'
711
import { CreateComponentPublicInstance } from './v3-component-public-instance'
812
export { ComponentPropsOptions } from './v3-component-props'
913

@@ -60,7 +64,8 @@ type ExtractOptionProp<T> = T extends ComponentOptionsBase<
6064
any, // M
6165
any, // Mixin
6266
any, // Extends
63-
any // EmitsOptions
67+
any, // EmitsOptions
68+
any // Defaults
6469
>
6570
? unknown extends P
6671
? {}
@@ -76,10 +81,11 @@ export interface ComponentOptionsBase<
7681
Mixin extends ComponentOptionsMixin,
7782
Extends extends ComponentOptionsMixin,
7883
Emits extends EmitsOptions,
79-
EmitNames extends string = string
84+
EmitNames extends string = string,
85+
Defaults = {}
8086
> extends Omit<
8187
Vue2ComponentOptions<Vue, D, M, C, Props>,
82-
'data' | 'computed' | 'method' | 'setup' | 'props' | 'mixins' | 'extends'
88+
'data' | 'computed' | 'methods' | 'setup' | 'props' | 'mixins' | 'extends'
8389
>,
8490
ComponentCustomOptions {
8591
// rewrite options api types
@@ -88,6 +94,7 @@ export interface ComponentOptionsBase<
8894
vm: CreateComponentPublicInstance<Props, {}, {}, {}, M, Mixin, Extends>
8995
) => D
9096
computed?: C
97+
methods?: M
9198
mixins?: Mixin[]
9299
extends?: Extends
93100
emits?: (Emits | EmitNames[]) & ThisType<void>
@@ -102,6 +109,8 @@ export interface ComponentOptionsBase<
102109
RawBindings,
103110
Emits
104111
>
112+
113+
__defaults?: Defaults
105114
}
106115

107116
export type ComponentOptionsMixin = ComponentOptionsBase<
@@ -112,6 +121,8 @@ export type ComponentOptionsMixin = ComponentOptionsBase<
112121
any,
113122
any,
114123
any,
124+
any,
125+
any,
115126
any
116127
>
117128

@@ -133,7 +144,8 @@ export type ComponentOptionsWithProps<
133144
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
134145
Emits extends EmitsOptions = {},
135146
EmitsNames extends string = string,
136-
Props = ExtractPropTypes<PropsOptions>
147+
Props = ExtractPropTypes<PropsOptions>,
148+
Defaults = ExtractDefaultPropTypes<PropsOptions>
137149
> = ComponentOptionsBase<
138150
Props,
139151
RawBindings,
@@ -143,7 +155,8 @@ export type ComponentOptionsWithProps<
143155
Mixin,
144156
Extends,
145157
Emits,
146-
EmitsNames
158+
EmitsNames,
159+
Defaults
147160
> & {
148161
props?: PropsOptions
149162
} & ThisType<
@@ -179,7 +192,8 @@ export type ComponentOptionsWithArrayProps<
179192
Mixin,
180193
Extends,
181194
Emits,
182-
EmitsNames
195+
EmitsNames,
196+
{}
183197
> & {
184198
props?: PropNames[]
185199
} & ThisType<
@@ -214,7 +228,8 @@ export type ComponentOptionsWithoutProps<
214228
Mixin,
215229
Extends,
216230
Emits,
217-
EmitsNames
231+
EmitsNames,
232+
{}
218233
> & {
219234
props?: undefined
220235
} & ThisType<

types/v3-component-public-instance.d.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ type MixinToOptionTypes<T> = T extends ComponentOptionsBase<
7070
infer Mixin,
7171
infer Extends,
7272
any,
73-
any
73+
any,
74+
infer Defaults
7475
>
75-
? OptionTypesType<P & {}, B & {}, D & {}, C & {}, M & {}> &
76+
? OptionTypesType<P & {}, B & {}, D & {}, C & {}, M & {}, Defaults & {}> &
7677
IntersectionMixin<Mixin> &
7778
IntersectionMixin<Extends>
7879
: never
@@ -83,7 +84,7 @@ type ExtractMixin<T> = {
8384
}[T extends ComponentOptionsMixin ? 'Mixin' : never]
8485

8586
type IntersectionMixin<T> = IsDefaultMixinComponent<T> extends true
86-
? OptionTypesType<{}, {}, {}, {}, {}>
87+
? OptionTypesType<{}, {}, {}, {}, {}, {}>
8788
: UnionToIntersection<ExtractMixin<T>>
8889

8990
type UnwrapMixinsType<
@@ -139,7 +140,18 @@ export type ComponentPublicInstance<
139140
PublicProps = P,
140141
Defaults = {},
141142
MakeDefaultsOptional extends boolean = false,
142-
Options = ComponentOptionsBase<any, any, any, any, any, any, any, any, any>
143+
Options = ComponentOptionsBase<
144+
any,
145+
any,
146+
any,
147+
any,
148+
any,
149+
any,
150+
any,
151+
any,
152+
any,
153+
any
154+
>
143155
> = {
144156
// $: ComponentInternalInstance
145157
$data: D

types/v3-define-component.d.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,18 @@ type DefineComponent<
5252
> &
5353
Props
5454
> &
55-
ComponentOptionsBase<Props, RawBindings, D, C, M, Mixin, Extends, E, EE> &
56-
Component & {
55+
ComponentOptionsBase<
56+
Props,
57+
RawBindings,
58+
D,
59+
C,
60+
M,
61+
Mixin,
62+
Extends,
63+
E,
64+
EE,
65+
Defaults
66+
> & {
5767
props: PropsOrPropOptions
5868
}
5969

0 commit comments

Comments
 (0)