Amour1688
4 years ago
2 changed files with 24 additions and 0 deletions
@ -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…
Reference in new issue