import { PropType } from 'vue'; import { VueTypeValidableDef, VueTypeDef } from 'vue-types'; const initDefaultProps = ( types: T, defaultProps: { [K in keyof T]?: T[K] extends VueTypeValidableDef ? U : T[K] extends VueTypeDef ? U : T[K] extends { type: PropType } ? U : any; }, ): T => { const propTypes: T = { ...types } as 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;