fix(types): fix some type errors

This commit is contained in:
vben 2021-08-13 00:12:51 +08:00
parent bb89c5059c
commit 9035fd191e
10 changed files with 24 additions and 25 deletions

View File

@ -8,6 +8,7 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import type { Ref } from 'vue';
import type { Definition } from '@logicflow/core'; import type { Definition } from '@logicflow/core';
import { defineComponent, ref, onMounted, unref, nextTick, computed, watch } from 'vue'; import { defineComponent, ref, onMounted, unref, nextTick, computed, watch } from 'vue';
import FlowChartToolbar from './FlowChartToolbar.vue'; import FlowChartToolbar from './FlowChartToolbar.vue';
@ -46,10 +47,10 @@
}, },
}, },
setup(props) { setup(props) {
const lfElRef = ref<ElRef>(null); const lfElRef = ref(null);
const graphData = ref<Recordable>({}); const graphData = ref({});
const lfInstance = ref<Nullable<LogicFlow>>(null); const lfInstance = ref(null) as Ref<LogicFlow | null>;
const { prefixCls } = useDesign('flow-chart'); const { prefixCls } = useDesign('flow-chart');
const appStore = useAppStore(); const appStore = useAppStore();

View File

@ -32,7 +32,7 @@ export function useLoading(
const instance = createLoading(props, undefined, true); const instance = createLoading(props, undefined, true);
const open = (): void => { const open = (): void => {
const t = unref(target); const t = unref(target as Ref<ElRef>);
if (!t) return; if (!t) return;
instance.open(t); instance.open(t);
}; };

View File

@ -1,6 +1,5 @@
<script lang="tsx"> <script lang="tsx">
import { defineComponent, ref, unref, computed, reactive, watchEffect } from 'vue'; import { defineComponent, ref, unref, computed, reactive, watchEffect } from 'vue';
import { Props } from './typing';
import { CloseOutlined, LeftOutlined, RightOutlined } from '@ant-design/icons-vue'; import { CloseOutlined, LeftOutlined, RightOutlined } from '@ant-design/icons-vue';
import resumeSvg from '/@/assets/svg/preview/resume.svg'; import resumeSvg from '/@/assets/svg/preview/resume.svg';
import rotateSvg from '/@/assets/svg/preview/p-rotate.svg'; import rotateSvg from '/@/assets/svg/preview/p-rotate.svg';
@ -57,7 +56,7 @@
name: 'ImagePreview', name: 'ImagePreview',
props, props,
emits: ['img-load', 'img-error'], emits: ['img-load', 'img-error'],
setup(props: Props, { expose, emit }) { setup(props, { expose, emit }) {
interface stateInfo { interface stateInfo {
scale: number; scale: number;
rotate: number; rotate: number;
@ -117,8 +116,9 @@
} }
const getScaleStep = computed(() => { const getScaleStep = computed(() => {
if (props.scaleStep > 0 && props.scaleStep < 100) { const scaleStep = props?.scaleStep ?? 0;
return props.scaleStep / 100; if (scaleStep ?? (0 > 0 && scaleStep < 100)) {
return scaleStep / 100;
} else { } else {
return imgState.imgScale / 10; return imgState.imgScale / 10;
} }
@ -164,7 +164,7 @@
img.src = url; img.src = url;
img.onload = (e: Event) => { img.onload = (e: Event) => {
if (imgState.currentUrl !== url) { if (imgState.currentUrl !== url) {
const ele: HTMLElement[] = e.composedPath(); const ele: any[] = e.composedPath();
if (props.rememberState) { if (props.rememberState) {
// //
stateMap.set(imgState.currentUrl, { stateMap.set(imgState.currentUrl, {
@ -244,7 +244,7 @@
setRotate: (rotate: number) => { setRotate: (rotate: number) => {
imgState.imgRotate = rotate; imgState.imgRotate = rotate;
}, },
} as PreviewActions); });
// //
function handleChange(direction: 'left' | 'right') { function handleChange(direction: 'left' | 'right') {

View File

@ -91,10 +91,10 @@
'columns-change', 'columns-change',
], ],
setup(props, { attrs, emit, slots, expose }) { setup(props, { attrs, emit, slots, expose }) {
const tableElRef = ref<ComponentRef>(null); const tableElRef = ref(null);
const tableData = ref<Recordable[]>([]); const tableData = ref<Recordable[]>([]);
const wrapRef = ref<Nullable<HTMLDivElement>>(null); const wrapRef = ref(null);
const innerPropsRef = ref<Partial<BasicTableProps>>(); const innerPropsRef = ref<Partial<BasicTableProps>>();
const { prefixCls } = useDesign('basic-table'); const { prefixCls } = useDesign('basic-table');

View File

@ -282,7 +282,7 @@
nextTick(() => { nextTick(() => {
const columnListEl = unref(columnListRef); const columnListEl = unref(columnListRef);
if (!columnListEl) return; if (!columnListEl) return;
const el = columnListEl.$el; const el = columnListEl.$el as any;
if (!el) return; if (!el) return;
// Drag and drop sort // Drag and drop sort
const { initSortable } = useSortable(el, { const { initSortable } = useSortable(el, {

View File

@ -66,6 +66,7 @@ export function useTableScroll(
if (!bodyEl) { if (!bodyEl) {
bodyEl = tableEl.querySelector('.ant-table-body'); bodyEl = tableEl.querySelector('.ant-table-body');
if (!bodyEl) return;
} }
const hasScrollBarY = bodyEl.scrollHeight > bodyEl.clientHeight; const hasScrollBarY = bodyEl.scrollHeight > bodyEl.clientHeight;

View File

@ -1,7 +1,8 @@
import { ref, onBeforeUpdate, Ref } from 'vue'; import type { Ref } from 'vue';
import { ref, onBeforeUpdate } from 'vue';
export function useRefs(): [Ref<HTMLElement[]>, (index: number) => (el: HTMLElement) => void] { export function useRefs(): [Ref<HTMLElement[]>, (index: number) => (el: HTMLElement) => void] {
const refs = ref<HTMLElement[]>([]); const refs = ref([]) as Ref<HTMLElement[]>;
onBeforeUpdate(() => { onBeforeUpdate(() => {
refs.value = []; refs.value = [];

View File

@ -1,10 +1,8 @@
import type { Ref } from 'vue'; import type { Ref } from 'vue';
import { ref, watch, unref } from 'vue'; import { ref, watch, unref } from 'vue';
import { useThrottleFn, useDebounceFn } from '@vueuse/core'; import { useThrottleFn, useDebounceFn } from '@vueuse/core';
export type RemoveEventFn = () => void; export type RemoveEventFn = () => void;
export interface UseEventParams { export interface UseEventParams {
el?: Element | Ref<Element | undefined> | Window | any; el?: Element | Ref<Element | undefined> | Window | any;
name: string; name: string;
@ -28,7 +26,7 @@ export function useEventListener({
const isAddRef = ref(false); const isAddRef = ref(false);
if (el) { if (el) {
const element: Ref<Element> = ref(el as Element); const element = ref(el as Element) as Ref<Element>;
const handler = isDebounce ? useDebounceFn(listener, wait) : useThrottleFn(listener, wait); const handler = isDebounce ? useDebounceFn(listener, wait) : useThrottleFn(listener, wait);
const realHandler = wait ? handler : listener; const realHandler = wait ? handler : listener;

View File

@ -1,13 +1,11 @@
import type { EChartsOption } from 'echarts'; import type { EChartsOption } from 'echarts';
import type { Ref } from 'vue'; import type { Ref } from 'vue';
import { useTimeoutFn } from '/@/hooks/core/useTimeout'; import { useTimeoutFn } from '/@/hooks/core/useTimeout';
import { tryOnUnmounted } from '@vueuse/core'; import { tryOnUnmounted } from '@vueuse/core';
import { unref, nextTick, watch, computed, ref } from 'vue'; import { unref, nextTick, watch, computed, ref } from 'vue';
import { useDebounceFn } from '@vueuse/core'; import { useDebounceFn } from '@vueuse/core';
import { useEventListener } from '/@/hooks/event/useEventListener'; import { useEventListener } from '/@/hooks/event/useEventListener';
import { useBreakpoint } from '/@/hooks/event/useBreakpoint'; import { useBreakpoint } from '/@/hooks/event/useBreakpoint';
import echarts from '/@/utils/lib/echarts'; import echarts from '/@/utils/lib/echarts';
import { useRootSetting } from '/@/hooks/setting/useRootSetting'; import { useRootSetting } from '/@/hooks/setting/useRootSetting';
@ -18,19 +16,19 @@ export function useECharts(
const { getDarkMode } = useRootSetting(); const { getDarkMode } = useRootSetting();
let chartInstance: echarts.ECharts | null = null; let chartInstance: echarts.ECharts | null = null;
let resizeFn: Fn = resize; let resizeFn: Fn = resize;
const cacheOptions = ref<EChartsOption>({}); const cacheOptions = ref({}) as Ref<EChartsOption>;
let removeResizeFn: Fn = () => {}; let removeResizeFn: Fn = () => {};
resizeFn = useDebounceFn(resize, 200); resizeFn = useDebounceFn(resize, 200);
const getOptions = computed((): EChartsOption => { const getOptions = computed(() => {
if (getDarkMode.value !== 'dark') { if (getDarkMode.value !== 'dark') {
return cacheOptions.value; return cacheOptions.value as EChartsOption;
} }
return { return {
backgroundColor: 'transparent', backgroundColor: 'transparent',
...cacheOptions.value, ...cacheOptions.value,
}; } as EChartsOption;
}); });
function initCharts(t = theme) { function initCharts(t = theme) {

View File

@ -84,7 +84,7 @@ export function isElement(val: unknown): val is Element {
return isObject(val) && !!val.tagName; return isObject(val) && !!val.tagName;
} }
export function isMap(val: unknown): val is Map { export function isMap(val: unknown): val is Map<any, any> {
return is(val, 'Map'); return is(val, 'Map');
} }