From 7678aa64e2cbb8e572079d1d13ddd1a2ec29bff2 Mon Sep 17 00:00:00 2001 From: xiaoxian521 <1923740402@qq.com> Date: Wed, 1 Mar 2023 20:03:47 +0800 Subject: [PATCH] chore: update `propTypes` --- src/utils/propTypes.ts | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/utils/propTypes.ts b/src/utils/propTypes.ts index 403b78b..cc7b16f 100644 --- a/src/utils/propTypes.ts +++ b/src/utils/propTypes.ts @@ -1,5 +1,10 @@ -import { CSSProperties, VNodeChild } from "vue"; -import { createTypes, VueTypeValidableDef, VueTypesInterface } from "vue-types"; +import type { CSSProperties, VNodeChild } from "vue"; +import { + createTypes, + toValidableType, + VueTypesInterface, + VueTypeValidableDef +} from "vue-types"; export type VueNode = VNodeChild | JSX.Element; @@ -8,7 +13,7 @@ type PropTypes = VueTypesInterface & { readonly VNodeChild: VueTypeValidableDef; }; -const propTypes = createTypes({ +const newPropTypes = createTypes({ func: undefined, bool: undefined, string: undefined, @@ -17,18 +22,18 @@ const propTypes = createTypes({ integer: undefined }) as PropTypes; -propTypes.extend([ - { - name: "style", - getter: true, - type: [String, Object], - default: undefined - }, - { - name: "VNodeChild", - getter: true, - type: undefined +// 从 vue-types v5.0 开始,extend()方法已经废弃,当前已改为官方推荐的ES6+方法 https://dwightjack.github.io/vue-types/advanced/extending-vue-types.html#the-extend-method +export default class propTypes extends newPropTypes { + // a native-like validator that supports the `.validable` method + static get style() { + return toValidableType("style", { + type: [String, Object] + }); } -]); -export { propTypes }; + static get VNodeChild() { + return toValidableType("VNodeChild", { + type: undefined + }); + } +}