Commit 02d41197b6555b20f3b084abacb9e32affbcbcc1
Committed by
GitHub
1 parent
84a5fc12
fix: propTypes.extend()方法已经废弃, 改为官方推荐的ES6+方法 (#2670)
Co-authored-by: 苗大 <caoshengmiao@hypergryph.com>
Showing
1 changed file
with
17 additions
and
16 deletions
src/utils/propTypes.ts
1 | 1 | import { CSSProperties, VNodeChild } from 'vue'; |
2 | -import { createTypes, VueTypeValidableDef, VueTypesInterface } from 'vue-types'; | |
2 | +import { createTypes, VueTypeValidableDef, VueTypesInterface, toValidableType } from 'vue-types'; | |
3 | 3 | |
4 | 4 | export type VueNode = VNodeChild | JSX.Element; |
5 | 5 | |
... | ... | @@ -8,8 +8,7 @@ type PropTypes = VueTypesInterface & { |
8 | 8 | readonly VNodeChild: VueTypeValidableDef<VueNode>; |
9 | 9 | // readonly trueBool: VueTypeValidableDef<boolean>; |
10 | 10 | }; |
11 | - | |
12 | -const propTypes = createTypes({ | |
11 | +const newPropTypes = createTypes({ | |
13 | 12 | func: undefined, |
14 | 13 | bool: undefined, |
15 | 14 | string: undefined, |
... | ... | @@ -18,17 +17,19 @@ const propTypes = createTypes({ |
18 | 17 | integer: undefined, |
19 | 18 | }) as PropTypes; |
20 | 19 | |
21 | -propTypes.extend([ | |
22 | - { | |
23 | - name: 'style', | |
24 | - getter: true, | |
25 | - type: [String, Object], | |
26 | - default: undefined, | |
27 | - }, | |
28 | - { | |
29 | - name: 'VNodeChild', | |
30 | - getter: true, | |
31 | - type: undefined, | |
32 | - }, | |
33 | -]); | |
20 | +// 从 vue-types v5.0 开始,extend()方法已经废弃,当前已改为官方推荐的ES6+方法 https://dwightjack.github.io/vue-types/advanced/extending-vue-types.html#the-extend-method | |
21 | +class propTypes extends newPropTypes { | |
22 | + // a native-like validator that supports the `.validable` method | |
23 | + static get style() { | |
24 | + return toValidableType('style', { | |
25 | + type: [String, Object], | |
26 | + }); | |
27 | + } | |
28 | + | |
29 | + static get VNodeChild() { | |
30 | + return toValidableType('VNodeChild', { | |
31 | + type: undefined, | |
32 | + }); | |
33 | + } | |
34 | +} | |
34 | 35 | export { propTypes }; | ... | ... |