File tree Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Expand file tree Collapse file tree 2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ const focusDirective: Directive = {
9
9
10
10
interface Foo_Props {
11
11
size : 'small' | 'large'
12
+ modelValue ?: string
13
+ 'onUpdate:modelValue' ?: ( val : string ) => void
12
14
// 组件的slots
13
15
slots : {
14
16
item ( name : string ) : VNodeChild
@@ -17,9 +19,8 @@ interface Foo_Props {
17
19
18
20
class Foo extends VueComponent < Foo_Props > {
19
21
// vue需要的运行时属性检查
20
- static defaultProps : ComponentProps < Foo_Props > = {
21
- size : String ,
22
- }
22
+ static defaultProps : ComponentProps < Foo_Props > = [ 'size' , 'modelValue' , 'onUpdate:modelValue' ]
23
+
23
24
// 组件需要的局部指令
24
25
static directives : Record < string , Directive > = {
25
26
focus : focusDirective ,
Original file line number Diff line number Diff line change @@ -53,9 +53,12 @@ type ModelProps<T extends {}> = Exclude<
53
53
undefined
54
54
>
55
55
56
- export type WithVModel < T extends { } , U extends keyof T = ModelProps < T > > = {
56
+ export type WithVModel < T extends { } , U extends keyof T = ModelProps < T > > = TransformModelValue < {
57
57
[ k in U as `v-model:${k & string } `] ?: T [ k ] | [ T [ k ] , string [ ] ]
58
- }
58
+ } >
59
+ export type TransformModelValue < T extends { } > = 'v-model:modelValue' extends keyof T
60
+ ? Omit < T , 'v-model:modelValue' > & { [ 'v-model' ] ?: T [ 'v-model:modelValue' ] }
61
+ : T
59
62
60
63
export type ComponentProps < T extends { } > = ComponentPropsArray < T > | ComponentPropsObject < T >
61
64
You can’t perform that action at this time.
0 commit comments