PropType
export type ButtonType = 'default'
| 'primary'
| 'success'
| 'warning'
| 'danger';
export const makeStringProp = (defaultVal: T) => {
type: String as unknown as PropType,
default: defaultVal
};
export const makeArrayProp = () => ({
type: Array as PropType,
default: () => [],
});
export const truthProp = {
type: Boolean,
default: true as const,
};
export default defineComponent({
props: {
title: makeStringProp('default'),
tag: makeStringProp('button'),
}
});
// 2
import type {PropType} from 'vue';
export interface TodoItem {
text: string
done: boolean
}
props: {
todo: {
type: Object as PropType,
default: {
text: '',
done: false
}
}
}
双重断言
basarat.gitbook.io/typescript/…
|