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 = {
99
1010interface Foo_Props {
1111 size : 'small' | 'large'
12+ modelValue ?: string
13+ 'onUpdate:modelValue' ?: ( val : string ) => void
1214 // 组件的slots
1315 slots : {
1416 item ( name : string ) : VNodeChild
@@ -17,9 +19,8 @@ interface Foo_Props {
1719
1820class Foo extends VueComponent < Foo_Props > {
1921 // vue需要的运行时属性检查
20- static defaultProps : ComponentProps < Foo_Props > = {
21- size : String ,
22- }
22+ static defaultProps : ComponentProps < Foo_Props > = [ 'size' , 'modelValue' , 'onUpdate:modelValue' ]
23+
2324 // 组件需要的局部指令
2425 static directives : Record < string , Directive > = {
2526 focus : focusDirective ,
Original file line number Diff line number Diff line change @@ -53,9 +53,12 @@ type ModelProps<T extends {}> = Exclude<
5353 undefined
5454>
5555
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 < {
5757 [ 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
5962
6063export type ComponentProps < T extends { } > = ComponentPropsArray < T > | ComponentPropsObject < T >
6164
You can’t perform that action at this time.
0 commit comments