Browse Source

chore: initDefaultProps type

pull/2992/head
Amour1688 4 years ago
parent
commit
88d3b6010b
  1. 0
      components/_util/props-util/index.js
  2. 24
      components/_util/props-util/initDefaultProps.ts

0
components/_util/props-util.js → components/_util/props-util/index.js

24
components/_util/props-util/initDefaultProps.ts

@ -0,0 +1,24 @@
import { VueTypeValidableDef, VueTypeDef } from 'vue-types';
const initDefaultProps = <T>(
propTypes: T,
defaultProps: {
[K in keyof T]?: T[K] extends VueTypeValidableDef<infer U>
? U
: T[K] extends VueTypeDef<infer U>
? U
: any;
},
): T => {
Object.keys(defaultProps).forEach(k => {
const prop = propTypes[k] as VueTypeValidableDef;
if (prop) {
prop.default = defaultProps[k];
} else {
throw new Error(`not have ${k} prop`);
}
});
return propTypes;
};
export default initDefaultProps;
Loading…
Cancel
Save