From 02d41197b6555b20f3b084abacb9e32affbcbcc1 Mon Sep 17 00:00:00 2001 From: Cherelle Spencer <454690789@qq.com> Date: Tue, 4 Apr 2023 16:59:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20propTypes.extend()=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E5=BA=9F=E5=BC=83,=20=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=AE=98=E6=96=B9=E6=8E=A8=E8=8D=90=E7=9A=84ES6+=E6=96=B9?= =?UTF-8?q?=E6=B3=95=20(#2670)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 苗大 --- src/utils/propTypes.ts | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/utils/propTypes.ts b/src/utils/propTypes.ts index a5b0a47a4..16cf9cd40 100644 --- a/src/utils/propTypes.ts +++ b/src/utils/propTypes.ts @@ -1,5 +1,5 @@ import { CSSProperties, VNodeChild } from 'vue'; -import { createTypes, VueTypeValidableDef, VueTypesInterface } from 'vue-types'; +import { createTypes, VueTypeValidableDef, VueTypesInterface, toValidableType } from 'vue-types'; export type VueNode = VNodeChild | JSX.Element; @@ -8,8 +8,7 @@ type PropTypes = VueTypesInterface & { readonly VNodeChild: VueTypeValidableDef; // readonly trueBool: VueTypeValidableDef; }; - -const propTypes = createTypes({ +const newPropTypes = createTypes({ func: undefined, bool: undefined, string: undefined, @@ -18,17 +17,19 @@ 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 +class propTypes extends newPropTypes { + // a native-like validator that supports the `.validable` method + static get style() { + return toValidableType('style', { + type: [String, Object], + }); + } + + static get VNodeChild() { + return toValidableType('VNodeChild', { + type: undefined, + }); + } +} export { propTypes };