Browse Source

perf: propTypes

xingyu 1 year ago
parent
commit
5da9b660bd
1 changed files with 10 additions and 14 deletions
  1. 10 14
      src/utils/propTypes.ts

+ 10 - 14
src/utils/propTypes.ts

@@ -1,12 +1,10 @@
-import { createTypes, VueTypesInterface, VueTypeValidableDef } from 'vue-types'
+import { VueTypeValidableDef, VueTypesInterface, createTypes, toValidableType } from 'vue-types'
 import { CSSProperties } from 'vue'
 
-// 自定义扩展vue-types
 type PropTypes = VueTypesInterface & {
   readonly style: VueTypeValidableDef<CSSProperties>
 }
-
-const propTypes = createTypes({
+const newPropTypes = createTypes({
   func: undefined,
   bool: undefined,
   string: undefined,
@@ -15,14 +13,12 @@ const propTypes = createTypes({
   integer: undefined
 }) as PropTypes
 
-// 需要自定义扩展的类型
-// see: https://dwightjack.github.io/vue-types/advanced/extending-vue-types.html#the-extend-method
-// propTypes.extend([
-//   {
-//     name: 'style',
-//     getter: true,
-//     type: [String, Object],
-//     default: undefined
-//   }
-// ])
+class propTypes extends newPropTypes {
+  static get style() {
+    return toValidableType('style', {
+      type: [String, Object]
+    })
+  }
+}
+
 export { propTypes }