diff --git a/example/example.tsx b/example/example.tsx index 28841c5..4d1860e 100644 --- a/example/example.tsx +++ b/example/example.tsx @@ -9,6 +9,8 @@ const focusDirective: Directive = { interface Foo_Props { size: 'small' | 'large' + modelValue?: string + 'onUpdate:modelValue'?: (val: string) => void // 组件的slots slots: { item(name: string): VNodeChild @@ -17,9 +19,8 @@ interface Foo_Props { class Foo extends VueComponent { // vue需要的运行时属性检查 - static defaultProps: ComponentProps = { - size: String, - } + static defaultProps: ComponentProps = ['size', 'modelValue', 'onUpdate:modelValue'] + // 组件需要的局部指令 static directives: Record = { focus: focusDirective, diff --git a/src/type.ts b/src/type.ts index 440653b..d774bb4 100644 --- a/src/type.ts +++ b/src/type.ts @@ -53,9 +53,12 @@ type ModelProps = Exclude< undefined > -export type WithVModel> = { +export type WithVModel> = TransformModelValue<{ [k in U as `v-model:${k & string}`]?: T[k] | [T[k], string[]] -} +}> +export type TransformModelValue = 'v-model:modelValue' extends keyof T + ? Omit & { ['v-model']?: T['v-model:modelValue'] } + : T export type ComponentProps = ComponentPropsArray | ComponentPropsObject