types(Badge): improve typing

This commit is contained in:
chenjiahan 2020-08-23 12:07:37 +08:00
parent d86238f071
commit 1b96a45d0b
2 changed files with 9 additions and 4 deletions

View File

@ -2,13 +2,18 @@ import { isDef, createNamespace } from '../utils';
const [createComponent, bem] = createNamespace('badge');
export type BadgeProps = {
dot?: boolean;
badge?: number | string;
};
export default createComponent({
props: {
dot: Boolean,
badge: [Number, String],
},
setup(props) {
setup(props: BadgeProps) {
return () => {
const { dot, badge } = props;
const hasBadge = isDef(badge) && badge !== '';

View File

@ -2,16 +2,16 @@
* Create a basic component with common options
*/
import { camelize } from '../format/string';
import type { App, ComponentOptions } from 'vue';
import { App, defineComponent, ComponentOptionsWithObjectProps } from 'vue';
export function createComponent(name: string) {
return function (sfc: ComponentOptions) {
return function (sfc: ComponentOptionsWithObjectProps) {
sfc.name = name;
sfc.install = (app: App) => {
app.component(name as string, sfc);
app.component(camelize(`-${name}`), sfc);
};
return sfc;
return defineComponent(sfc);
};
}