refactor: refine emits type declaration

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/599/head
Ryan Wang 2022-08-15 20:31:51 +08:00
parent cf85449b25
commit 021e9a8a93
35 changed files with 143 additions and 35 deletions

View File

@ -31,7 +31,9 @@ const props = withDefaults(
}
);
const emit = defineEmits(["close"]);
const emit = defineEmits<{
(event: "close"): void;
}>();
const classes = computed(() => {
return [`alert-${props.type}`];

View File

@ -61,7 +61,9 @@ const props = withDefaults(
);
const router = useRouter();
const emit = defineEmits(["click"]);
const emit = defineEmits<{
(event: "click"): void;
}>();
const classes = computed(() => {
return [

View File

@ -15,7 +15,10 @@ const id = ["checkbox", props.name, props.value]
.filter((item) => !!item)
.join("-");
const emit = defineEmits(["update:checked", "change"]);
const emit = defineEmits<{
(event: "update:checked", value: boolean): void;
(event: "change", value: Event): void;
}>();
function handleChange(e: Event) {
const { checked } = e.target as HTMLInputElement;

View File

@ -16,7 +16,10 @@ const props = withDefaults(
}
);
const emit = defineEmits(["update:modelValue", "change"]);
const emit = defineEmits<{
(event: "update:modelValue", value: string[]): void;
(event: "change", value: string[]): void;
}>();
function handleChange(e: Event) {
const { value, checked } = e.target as HTMLInputElement;

View File

@ -35,7 +35,10 @@ const props = withDefaults(
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
const icons = {
success: {

View File

@ -15,7 +15,9 @@ const props = withDefaults(
}
);
const emit = defineEmits(["update:modelValue"]);
const emit = defineEmits<{
(event: "update:modelValue", value: string): void;
}>();
const classes = computed(() => {
return [`input-${props.size}`];

View File

@ -15,7 +15,9 @@ const props = withDefaults(
}
);
const emit = defineEmits(["select"]);
const emit = defineEmits<{
(event: "select", id: string): void;
}>();
const slots = useSlots();

View File

@ -17,7 +17,10 @@ const props = withDefaults(
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", value: boolean): void;
(event: "close"): void;
}>();
const rootVisible = ref(false);
const modelWrapper = ref<HTMLElement>();

View File

@ -20,7 +20,11 @@ const { page, size, total } = toRefs(props);
const key = ref(Math.random());
const emit = defineEmits(["update:page", "update:size", "change"]);
const emit = defineEmits<{
(event: "update:page", page: number): void;
(event: "update:size", size: number): void;
(event: "change", value: { page: number; size: number }): void;
}>();
const onPageChange = ({
currentPage,

View File

@ -8,7 +8,10 @@ const props = defineProps<{
name?: string;
}>();
const emit = defineEmits(["update:modelValue", "change"]);
const emit = defineEmits<{
(event: "update:modelValue", value: string | number | boolean): void;
(event: "change", value: string | number | boolean): void;
}>();
const id = ["radio", props.name, props.value]
.filter((item) => !!item)

View File

@ -15,7 +15,10 @@ withDefaults(
}
);
const emit = defineEmits(["update:modelValue", "change"]);
const emit = defineEmits<{
(event: "update:modelValue", value: string | number | boolean): void;
(event: "change", value: string | number | boolean): void;
}>();
function handleChange(value: string | number | boolean) {
emit("update:modelValue", value);

View File

@ -15,7 +15,9 @@ const props = withDefaults(
}
);
const emit = defineEmits(["update:modelValue"]);
const emit = defineEmits<{
(event: "update:modelValue", value: string): void;
}>();
const classes = computed(() => {
return [`select-${props.size}`];

View File

@ -8,7 +8,10 @@ const props = withDefaults(
}
);
const emit = defineEmits(["update:modelValue", "change"]);
const emit = defineEmits<{
(event: "update:modelValue", value: boolean): void;
(event: "change", value: boolean): void;
}>();
const handleChange = () => {
emit("update:modelValue", !props.modelValue);

View File

@ -19,7 +19,10 @@ const props = withDefaults(
}
);
const emit = defineEmits(["update:activeId", "change"]);
const emit = defineEmits<{
(event: "update:activeId", value: number | string): void;
(event: "change", value: number | string): void;
}>();
const classes = computed(() => {
return [`tabbar-${props.type}`, `tabbar-direction-${props.direction}`];

View File

@ -25,7 +25,10 @@ provide<ComputedRef<string | number | undefined>>(
computed(() => props.activeId)
);
const emit = defineEmits(["update:activeId", "change"]);
const emit = defineEmits<{
(event: "update:activeId", value: number | string): void;
(event: "change", value: number | string): void;
}>();
const slots = useSlots();

View File

@ -12,7 +12,9 @@ withDefaults(
}
);
const emit = defineEmits(["update:modelValue"]);
const emit = defineEmits<{
(event: "update:modelValue", value: string): void;
}>();
function handleInput(e: Event) {
const { value } = e.target as HTMLInputElement;

View File

@ -10,7 +10,10 @@ withDefaults(
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
const onVisibleChange = (visible: boolean) => {
emit("update:visible", visible);

View File

@ -17,7 +17,10 @@ withDefaults(
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
const onVisibleChange = (visible: boolean) => {
emit("update:visible", visible);

View File

@ -10,7 +10,10 @@ withDefaults(
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
const onVisibleChange = (visible: boolean) => {
emit("update:visible", visible);

View File

@ -10,7 +10,10 @@ withDefaults(
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
const attachments = Array.from(new Array(50), (_, index) => index).map(
(index) => {

View File

@ -18,7 +18,11 @@ withDefaults(
visible: false,
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
const strategies = ref([
{

View File

@ -17,7 +17,10 @@ withDefaults(
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
const strategies = ref([
{

View File

@ -12,7 +12,10 @@ withDefaults(
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
const onVisibleChange = (visible: boolean) => {
emit("update:visible", visible);

View File

@ -27,7 +27,12 @@ const props = withDefaults(
}
);
const emit = defineEmits(["update:visible", "close", "previous", "next"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
(event: "previous"): void;
(event: "next"): void;
}>();
const settingActiveId = ref("general");
const formState = ref<FormState>({

View File

@ -11,7 +11,11 @@ withDefaults(
tag: undefined,
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
const onVisibleChange = (visible: boolean) => {
emit("update:visible", visible);

View File

@ -19,7 +19,10 @@ const props = withDefaults(
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
const initialFormState: Menu = {
spec: {

View File

@ -19,7 +19,11 @@ const props = withDefaults(
}
);
const emit = defineEmits(["update:visible", "close", "saved"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
(event: "saved", menuItem: MenuItem): void;
}>();
const initialFormState: MenuItem = {
spec: {

View File

@ -13,7 +13,11 @@ withDefaults(
}
);
const emit = defineEmits(["change", "open-editing", "delete"]);
const emit = defineEmits<{
(event: "change"): void;
(event: "open-editing", menuItem: MenuTreeItem): void;
(event: "delete", menuItem: MenuTreeItem): void;
}>();
const isDragging = ref(false);

View File

@ -21,7 +21,10 @@ const props = withDefaults(
}
);
const emit = defineEmits(["select", "update:selectedMenu"]);
const emit = defineEmits<{
(event: "select", menu: Menu): void;
(event: "update:selectedMenu", menu: Menu): void;
}>();
const menus = ref<Menu[]>([] as Menu[]);
const selectedMenuToUpdate = ref<Menu | null>(null);

View File

@ -15,7 +15,10 @@ withDefaults(
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
const handleVisibleChange = (visible: boolean) => {
emit("update:visible", visible);

View File

@ -26,7 +26,11 @@ withDefaults(
}
);
const emit = defineEmits(["update:visible", "close", "update:selectedTheme"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
(event: "update:selectedTheme", theme: Theme | null): void;
}>();
const themes = ref<Theme[]>([]);
const themeInstall = ref(false);

View File

@ -16,7 +16,10 @@ withDefaults(
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
const dialog = useDialog();

View File

@ -22,7 +22,10 @@ const props = withDefaults(
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
const { roleTemplateGroups, handleRoleTemplateSelect, selectedRoleTemplates } =
useRoleTemplateSelection();

View File

@ -29,7 +29,10 @@ const props = withDefaults(
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
interface FormState {
user: User;

View File

@ -16,7 +16,11 @@ const props = withDefaults(
}
);
const emit = defineEmits(["update:visible", "close"]);
const emit = defineEmits<{
(event: "update:visible", visible: boolean): void;
(event: "close"): void;
}>();
const currentUser = inject<User>("currentUser");
interface PasswordChangeFormState {