[improvement] make props less magic (#3775)
This commit is contained in:
@@ -25,26 +25,6 @@ export type TsxComponent<Props, Events, Slots> = (
|
||||
props: Partial<Props & Events & TsxBaseProps<Slots>>
|
||||
) => VNode;
|
||||
|
||||
const arrayProp = {
|
||||
type: Array,
|
||||
default: () => []
|
||||
};
|
||||
|
||||
const numberProp = {
|
||||
type: Number,
|
||||
default: 0
|
||||
};
|
||||
|
||||
function defaultProps(props: any) {
|
||||
Object.keys(props).forEach(key => {
|
||||
if (props[key] === Array) {
|
||||
props[key] = arrayProp;
|
||||
} else if (props[key] === Number) {
|
||||
props[key] = numberProp;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function install(this: ComponentOptions<Vue>, Vue: VueConstructor) {
|
||||
const { name } = this;
|
||||
Vue.component(name as string, this);
|
||||
@@ -89,10 +69,6 @@ export function createComponent(name: string) {
|
||||
sfc.mixins.push(SlotsMixin);
|
||||
}
|
||||
|
||||
if (sfc.props) {
|
||||
defaultProps(sfc.props);
|
||||
}
|
||||
|
||||
sfc.name = name;
|
||||
sfc.install = install;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user