From 42888a1c229ee7ff4874f50d40cfdd9cccf4a5e3 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 13 Aug 2021 09:59:44 +0800 Subject: [PATCH] types: using exact component instance type (#9256) --- src/address-edit/AddressEdit.tsx | 7 +++---- src/address-edit/AddressEditDetail.tsx | 5 +++-- src/area/Area.tsx | 10 ++++++---- src/calendar/test/index.spec.ts | 6 +++--- src/checkbox/demo/index.vue | 7 ++++--- src/count-down/demo/index.vue | 4 ++-- src/datetime-picker/DatePicker.tsx | 8 +++----- src/datetime-picker/TimePicker.tsx | 13 +++---------- src/dropdown-menu/demo/index.vue | 4 ++-- src/image-preview/ImagePreview.tsx | 5 ++--- src/picker/types.ts | 6 +++--- src/search/Search.tsx | 7 +++---- src/search/test/index.spec.ts | 6 +++--- src/tabs/TabsContent.tsx | 6 +++--- 14 files changed, 43 insertions(+), 51 deletions(-) diff --git a/src/address-edit/AddressEdit.tsx b/src/address-edit/AddressEdit.tsx index 1a70e3626..48beff53b 100644 --- a/src/address-edit/AddressEdit.tsx +++ b/src/address-edit/AddressEdit.tsx @@ -16,14 +16,13 @@ import { isMobile, truthProp, createNamespace, - ComponentInstance, } from '../utils'; // Composables import { useExpose } from '../composables/use-expose'; // Components -import { Area, AreaList, AreaColumnOption } from '../area'; +import { Area, AreaList, AreaColumnOption, AreaInstance } from '../area'; import { Cell } from '../cell'; import { Field } from '../field'; import { Popup } from '../popup'; @@ -120,7 +119,7 @@ export default defineComponent({ ], setup(props, { emit, slots }) { - const areaRef = ref(); + const areaRef = ref(); const state = reactive({ data: {} as AddressEditInfo, @@ -158,7 +157,7 @@ export default defineComponent({ const assignAreaValues = () => { if (areaRef.value) { - const detail = areaRef.value.getArea(); + const detail: Record = areaRef.value.getArea(); detail.areaCode = detail.code; delete detail.code; extend(state.data, detail); diff --git a/src/address-edit/AddressEditDetail.tsx b/src/address-edit/AddressEditDetail.tsx index b6d1ed0f8..45b78feb9 100644 --- a/src/address-edit/AddressEditDetail.tsx +++ b/src/address-edit/AddressEditDetail.tsx @@ -1,7 +1,7 @@ import { PropType, ref, defineComponent } from 'vue'; // Utils -import { isAndroid, ComponentInstance, createNamespace } from '../utils'; +import { isAndroid, createNamespace } from '../utils'; // Components import { Cell } from '../cell'; @@ -9,6 +9,7 @@ import { Field } from '../field'; // Types import type { AddressEditSearchItem } from './types'; +import type { FieldInstance } from '../field/types'; const [name, bem, t] = createNamespace('address-edit-detail'); const android = isAndroid(); @@ -30,7 +31,7 @@ export default defineComponent({ emits: ['blur', 'focus', 'input', 'select-search'], setup(props, { emit }) { - const field = ref(); + const field = ref(); const showSearchResult = () => props.focused && props.searchResult && props.showSearchResult; diff --git a/src/area/Area.tsx b/src/area/Area.tsx index 3b8a59d76..393102760 100644 --- a/src/area/Area.tsx +++ b/src/area/Area.tsx @@ -12,14 +12,14 @@ import { // Utils import { deepClone } from '../utils/deep-clone'; -import { pick, createNamespace, ComponentInstance, extend } from '../utils'; +import { pick, createNamespace, extend } from '../utils'; import { pickerProps } from '../picker/Picker'; // Composables import { useExpose } from '../composables/use-expose'; // Components -import { Picker } from '../picker'; +import { Picker, PickerInstance } from '../picker'; // Types import type { AreaList, AreaColumnType, AreaColumnOption } from './types'; @@ -80,7 +80,7 @@ export default defineComponent({ emits: ['change', 'confirm', 'cancel'], setup(props, { emit, slots }) { - const pickerRef = ref(); + const pickerRef = ref(); const state = reactive({ code: props.value, @@ -235,7 +235,9 @@ export default defineComponent({ const getValues = () => { if (pickerRef.value) { - const values = pickerRef.value.getValues().filter(Boolean); + const values = pickerRef.value + .getValues() + .filter(Boolean); return parseValues(values); } return []; diff --git a/src/calendar/test/index.spec.ts b/src/calendar/test/index.spec.ts index 750682199..6bbac63c0 100644 --- a/src/calendar/test/index.spec.ts +++ b/src/calendar/test/index.spec.ts @@ -2,7 +2,7 @@ import { Calendar, CalendarDayItem } from '..'; import { mount, later } from '../../../test'; import { getNextDay, getPrevDay } from '../utils'; import { now, minDate, maxDate } from './utils'; -import type { ComponentInstance } from '../../utils'; +import type { CalendarInstance } from '../types'; test('should reset to default date when calling reset method', async () => { const defaultDate = [minDate, getNextDay(minDate)]; @@ -21,7 +21,7 @@ test('should reset to default date when calling reset method', async () => { await days[15].trigger('click'); await days[18].trigger('click'); - (wrapper.vm as ComponentInstance).reset(); + (wrapper.vm as CalendarInstance).reset(); wrapper.find('.van-calendar__confirm').trigger('click'); expect(wrapper.emitted<[Date, Date]>('confirm')![0][0]).toEqual(defaultDate); @@ -44,7 +44,7 @@ test('should reset to specific date when calling reset method with date', async await days[18].trigger('click'); const newDate = [getPrevDay(maxDate), maxDate]; - (wrapper.vm as ComponentInstance).reset(newDate); + (wrapper.vm as CalendarInstance).reset(newDate); wrapper.find('.van-calendar__confirm').trigger('click'); expect(wrapper.emitted<[Date, Date]>('confirm')![0][0]).toEqual(newDate); diff --git a/src/checkbox/demo/index.vue b/src/checkbox/demo/index.vue index 93b4fb01c..8f4d7ae9b 100644 --- a/src/checkbox/demo/index.vue +++ b/src/checkbox/demo/index.vue @@ -2,7 +2,8 @@ import { ref, reactive } from 'vue'; import { useTranslate } from '@demo/use-translate'; import { useRefs } from '../../composables/use-refs'; -import { ComponentInstance } from '../../utils'; +import type { CheckboxInstance } from '../types'; +import type { CheckboxGroupInstance } from '../../checkbox-group'; const i18n = { 'zh-CN': { @@ -56,8 +57,8 @@ const state = reactive({ const activeIcon = 'https://img.yzcdn.cn/vant/user-active.png'; const inactiveIcon = 'https://img.yzcdn.cn/vant/user-inactive.png'; -const group = ref(); -const [refs, setRefs] = useRefs(); +const group = ref(); +const [refs, setRefs] = useRefs(); const toggle = (index: number) => { refs.value[index].toggle(); diff --git a/src/count-down/demo/index.vue b/src/count-down/demo/index.vue index 1a7a64402..3fee81b1e 100644 --- a/src/count-down/demo/index.vue +++ b/src/count-down/demo/index.vue @@ -1,8 +1,8 @@