chore: initDefaultProps type

pull/2992/head
Amour1688 2020-10-13 22:57:56 +08:00
parent 93b64061db
commit 88d3b6010b
2 changed files with 24 additions and 0 deletions

View File

@ -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;