types: improve ref typing (#8182)

This commit is contained in:
neverland 2021-02-19 20:58:02 +08:00 committed by GitHub
parent 7daca89102
commit 9ad0eafae0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 31 additions and 20 deletions

View File

@ -1,7 +1,7 @@
import { PropType, ref } from 'vue'; import { PropType, ref } from 'vue';
// Utils // Utils
import { createNamespace } from '../utils'; import { ComponentInstance, createNamespace } from '../utils';
import { isAndroid } from '../utils/validate/system'; import { isAndroid } from '../utils/validate/system';
// Components // Components
@ -31,7 +31,7 @@ export default createComponent({
emits: ['blur', 'focus', 'input', 'select-search'], emits: ['blur', 'focus', 'input', 'select-search'],
setup(props, { emit }) { setup(props, { emit }) {
const field = ref(); const field = ref<ComponentInstance>();
const showSearchResult = () => const showSearchResult = () =>
props.focused && props.searchResult && props.showSearchResult; props.focused && props.searchResult && props.showSearchResult;
@ -42,7 +42,7 @@ export default createComponent({
}; };
const onFinish = () => { const onFinish = () => {
field.value.blur(); field.value!.blur();
}; };
const renderFinish = () => { const renderFinish = () => {

View File

@ -1,7 +1,7 @@
import { ref, watch, computed, nextTick, reactive, PropType } from 'vue'; import { ref, watch, computed, nextTick, reactive, PropType } from 'vue';
// Utils // Utils
import { createNamespace, isObject } from '../utils'; import { ComponentInstance, createNamespace, isObject } from '../utils';
import { isMobile } from '../utils/validate/mobile'; import { isMobile } from '../utils/validate/mobile';
// Composition // Composition
@ -113,7 +113,7 @@ export default createComponent({
], ],
setup(props, { emit, slots }) { setup(props, { emit, slots }) {
const areaRef = ref(); const areaRef = ref<ComponentInstance>();
const state = reactive({ const state = reactive({
data: {} as AddressInfo, data: {} as AddressInfo,

View File

@ -55,8 +55,8 @@ export default createComponent({
setup(props, { emit }) { setup(props, { emit }) {
const [visible, setVisible] = useToggle(); const [visible, setVisible] = useToggle();
const daysRef = ref(); const daysRef = ref<HTMLElement>();
const monthRef = ref(); const monthRef = ref<HTMLElement>();
const height = useHeight(monthRef); const height = useHeight(monthRef);
const title = computed(() => formatMonthTitle(props.date)); const title = computed(() => formatMonthTitle(props.date));
@ -82,7 +82,7 @@ export default createComponent({
const el = props.showSubtitle ? daysRef.value : monthRef.value; const el = props.showSubtitle ? daysRef.value : monthRef.value;
const scrollTop = const scrollTop =
el.getBoundingClientRect().top - el!.getBoundingClientRect().top -
body.getBoundingClientRect().top + body.getBoundingClientRect().top +
body.scrollTop; body.scrollTop;

View File

@ -174,7 +174,7 @@ export default createComponent({
let bodyHeight: number; let bodyHeight: number;
const bodyRef = ref(); const bodyRef = ref<HTMLElement>();
const state = reactive({ const state = reactive({
subtitle: '', subtitle: '',
@ -219,7 +219,7 @@ export default createComponent({
// calculate the position of the elements // calculate the position of the elements
// and find the elements that needs to be rendered // and find the elements that needs to be rendered
const onScroll = () => { const onScroll = () => {
const top = getScrollTop(bodyRef.value); const top = getScrollTop(bodyRef.value!);
const bottom = top + bodyHeight; const bottom = top + bodyHeight;
const heights = months.value.map((item, index) => const heights = months.value.map((item, index) =>

View File

@ -2,7 +2,13 @@ import { ref, watch, computed, nextTick, onMounted, PropType } from 'vue';
// Utils // Utils
import { isDate } from '../utils/validate/date'; import { isDate } from '../utils/validate/date';
import { pick, range, padZero, createNamespace } from '../utils'; import {
pick,
range,
padZero,
createNamespace,
ComponentInstance,
} from '../utils';
import { import {
times, times,
ColumnType, ColumnType,
@ -57,7 +63,7 @@ export default createComponent({
return props.minDate; return props.minDate;
}; };
const picker = ref(); const picker = ref<ComponentInstance>();
const currentDate = ref(formatValue(props.modelValue)); const currentDate = ref(formatValue(props.modelValue));
const getBoundary = (type: 'max' | 'min', value: Date) => { const getBoundary = (type: 'max' | 'min', value: Date) => {
@ -207,13 +213,13 @@ export default createComponent({
}); });
nextTick(() => { nextTick(() => {
picker.value.setValues(values); picker.value!.setValues(values);
}); });
}; };
const updateInnerValue = () => { const updateInnerValue = () => {
const { type } = props; const { type } = props;
const indexes = picker.value.getIndexes(); const indexes = picker.value!.getIndexes();
const getValue = (type: ColumnType) => { const getValue = (type: ColumnType) => {
let index = 0; let index = 0;

View File

@ -26,7 +26,7 @@ export default createComponent({
active: false, active: false,
}); });
const root = ref(); const root = ref<HTMLElement>();
const { parent } = useParent<IndexBarProvide>(INDEX_BAR_KEY); const { parent } = useParent<IndexBarProvide>(INDEX_BAR_KEY);
if (!parent) { if (!parent) {

View File

@ -75,7 +75,7 @@ export default createComponent({
setup(props, { emit, slots }) { setup(props, { emit, slots }) {
const root = ref<HTMLElement>(); const root = ref<HTMLElement>();
const activeAnchor = ref(); const activeAnchor = ref('');
const touch = useTouch(); const touch = useTouch();
const scrollParent = useScrollParent(root); const scrollParent = useScrollParent(root);

View File

@ -1,7 +1,12 @@
import { ref, PropType, CSSProperties } from 'vue'; import { ref, PropType, CSSProperties } from 'vue';
// Utils // Utils
import { pick, createNamespace, preventDefault } from '../utils'; import {
pick,
createNamespace,
preventDefault,
ComponentInstance,
} from '../utils';
// Composition // Composition
import { useExpose } from '../composables/use-expose'; import { useExpose } from '../composables/use-expose';
@ -44,7 +49,7 @@ export default createComponent({
emits: ['update:modelValue', 'search', 'cancel'], emits: ['update:modelValue', 'search', 'cancel'],
setup(props, { emit, slots, attrs }) { setup(props, { emit, slots, attrs }) {
const filedRef = ref(); const filedRef = ref<ComponentInstance>();
const onCancel = () => { const onCancel = () => {
if (!slots.action) { if (!slots.action) {

View File

@ -1,5 +1,5 @@
import { ref, watch, onMounted } from 'vue'; import { ref, watch, onMounted } from 'vue';
import { createNamespace } from '../utils'; import { ComponentInstance, createNamespace } from '../utils';
import Swipe from '../swipe'; import Swipe from '../swipe';
const [createComponent, bem] = createNamespace('tabs'); const [createComponent, bem] = createNamespace('tabs');
@ -27,7 +27,7 @@ export default createComponent({
emits: ['change'], emits: ['change'],
setup(props, { emit, slots }) { setup(props, { emit, slots }) {
const swipeRef = ref(); const swipeRef = ref<ComponentInstance>();
const onChange = (index: number) => { const onChange = (index: number) => {
emit('change', index); emit('change', index);