Commit 9035fd191e4e8d954f42b3a4cd1e80ec70b7cbb6

Authored by vben
1 parent bb89c505

fix(types): fix some type errors

src/components/FlowChart/src/FlowChart.vue
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 </div> 8 </div>
9 </template> 9 </template>
10 <script lang="ts"> 10 <script lang="ts">
  11 + import type { Ref } from 'vue';
11 import type { Definition } from '@logicflow/core'; 12 import type { Definition } from '@logicflow/core';
12 import { defineComponent, ref, onMounted, unref, nextTick, computed, watch } from 'vue'; 13 import { defineComponent, ref, onMounted, unref, nextTick, computed, watch } from 'vue';
13 import FlowChartToolbar from './FlowChartToolbar.vue'; 14 import FlowChartToolbar from './FlowChartToolbar.vue';
@@ -46,10 +47,10 @@ @@ -46,10 +47,10 @@
46 }, 47 },
47 }, 48 },
48 setup(props) { 49 setup(props) {
49 - const lfElRef = ref<ElRef>(null);  
50 - const graphData = ref<Recordable>({}); 50 + const lfElRef = ref(null);
  51 + const graphData = ref({});
51 52
52 - const lfInstance = ref<Nullable<LogicFlow>>(null); 53 + const lfInstance = ref(null) as Ref<LogicFlow | null>;
53 54
54 const { prefixCls } = useDesign('flow-chart'); 55 const { prefixCls } = useDesign('flow-chart');
55 const appStore = useAppStore(); 56 const appStore = useAppStore();
src/components/Loading/src/useLoading.ts
@@ -32,7 +32,7 @@ export function useLoading( @@ -32,7 +32,7 @@ export function useLoading(
32 const instance = createLoading(props, undefined, true); 32 const instance = createLoading(props, undefined, true);
33 33
34 const open = (): void => { 34 const open = (): void => {
35 - const t = unref(target); 35 + const t = unref(target as Ref<ElRef>);
36 if (!t) return; 36 if (!t) return;
37 instance.open(t); 37 instance.open(t);
38 }; 38 };
src/components/Preview/src/Functional.vue
1 <script lang="tsx"> 1 <script lang="tsx">
2 import { defineComponent, ref, unref, computed, reactive, watchEffect } from 'vue'; 2 import { defineComponent, ref, unref, computed, reactive, watchEffect } from 'vue';
3 - import { Props } from './typing';  
4 import { CloseOutlined, LeftOutlined, RightOutlined } from '@ant-design/icons-vue'; 3 import { CloseOutlined, LeftOutlined, RightOutlined } from '@ant-design/icons-vue';
5 import resumeSvg from '/@/assets/svg/preview/resume.svg'; 4 import resumeSvg from '/@/assets/svg/preview/resume.svg';
6 import rotateSvg from '/@/assets/svg/preview/p-rotate.svg'; 5 import rotateSvg from '/@/assets/svg/preview/p-rotate.svg';
@@ -57,7 +56,7 @@ @@ -57,7 +56,7 @@
57 name: 'ImagePreview', 56 name: 'ImagePreview',
58 props, 57 props,
59 emits: ['img-load', 'img-error'], 58 emits: ['img-load', 'img-error'],
60 - setup(props: Props, { expose, emit }) { 59 + setup(props, { expose, emit }) {
61 interface stateInfo { 60 interface stateInfo {
62 scale: number; 61 scale: number;
63 rotate: number; 62 rotate: number;
@@ -117,8 +116,9 @@ @@ -117,8 +116,9 @@
117 } 116 }
118 117
119 const getScaleStep = computed(() => { 118 const getScaleStep = computed(() => {
120 - if (props.scaleStep > 0 && props.scaleStep < 100) {  
121 - return props.scaleStep / 100; 119 + const scaleStep = props?.scaleStep ?? 0;
  120 + if (scaleStep ?? (0 > 0 && scaleStep < 100)) {
  121 + return scaleStep / 100;
122 } else { 122 } else {
123 return imgState.imgScale / 10; 123 return imgState.imgScale / 10;
124 } 124 }
@@ -164,7 +164,7 @@ @@ -164,7 +164,7 @@
164 img.src = url; 164 img.src = url;
165 img.onload = (e: Event) => { 165 img.onload = (e: Event) => {
166 if (imgState.currentUrl !== url) { 166 if (imgState.currentUrl !== url) {
167 - const ele: HTMLElement[] = e.composedPath(); 167 + const ele: any[] = e.composedPath();
168 if (props.rememberState) { 168 if (props.rememberState) {
169 // 保存当前图片的缩放信息 169 // 保存当前图片的缩放信息
170 stateMap.set(imgState.currentUrl, { 170 stateMap.set(imgState.currentUrl, {
@@ -244,7 +244,7 @@ @@ -244,7 +244,7 @@
244 setRotate: (rotate: number) => { 244 setRotate: (rotate: number) => {
245 imgState.imgRotate = rotate; 245 imgState.imgRotate = rotate;
246 }, 246 },
247 - } as PreviewActions); 247 + });
248 248
249 // 上一页下一页 249 // 上一页下一页
250 function handleChange(direction: 'left' | 'right') { 250 function handleChange(direction: 'left' | 'right') {
src/components/Table/src/BasicTable.vue
@@ -91,10 +91,10 @@ @@ -91,10 +91,10 @@
91 'columns-change', 91 'columns-change',
92 ], 92 ],
93 setup(props, { attrs, emit, slots, expose }) { 93 setup(props, { attrs, emit, slots, expose }) {
94 - const tableElRef = ref<ComponentRef>(null); 94 + const tableElRef = ref(null);
95 const tableData = ref<Recordable[]>([]); 95 const tableData = ref<Recordable[]>([]);
96 96
97 - const wrapRef = ref<Nullable<HTMLDivElement>>(null); 97 + const wrapRef = ref(null);
98 const innerPropsRef = ref<Partial<BasicTableProps>>(); 98 const innerPropsRef = ref<Partial<BasicTableProps>>();
99 99
100 const { prefixCls } = useDesign('basic-table'); 100 const { prefixCls } = useDesign('basic-table');
src/components/Table/src/components/settings/ColumnSetting.vue
@@ -282,7 +282,7 @@ @@ -282,7 +282,7 @@
282 nextTick(() => { 282 nextTick(() => {
283 const columnListEl = unref(columnListRef); 283 const columnListEl = unref(columnListRef);
284 if (!columnListEl) return; 284 if (!columnListEl) return;
285 - const el = columnListEl.$el; 285 + const el = columnListEl.$el as any;
286 if (!el) return; 286 if (!el) return;
287 // Drag and drop sort 287 // Drag and drop sort
288 const { initSortable } = useSortable(el, { 288 const { initSortable } = useSortable(el, {
src/components/Table/src/hooks/useTableScroll.ts
@@ -66,6 +66,7 @@ export function useTableScroll( @@ -66,6 +66,7 @@ export function useTableScroll(
66 66
67 if (!bodyEl) { 67 if (!bodyEl) {
68 bodyEl = tableEl.querySelector('.ant-table-body'); 68 bodyEl = tableEl.querySelector('.ant-table-body');
  69 + if (!bodyEl) return;
69 } 70 }
70 71
71 const hasScrollBarY = bodyEl.scrollHeight > bodyEl.clientHeight; 72 const hasScrollBarY = bodyEl.scrollHeight > bodyEl.clientHeight;
src/hooks/core/useRefs.ts
1 -import { ref, onBeforeUpdate, Ref } from 'vue'; 1 +import type { Ref } from 'vue';
  2 +import { ref, onBeforeUpdate } from 'vue';
2 3
3 export function useRefs(): [Ref<HTMLElement[]>, (index: number) => (el: HTMLElement) => void] { 4 export function useRefs(): [Ref<HTMLElement[]>, (index: number) => (el: HTMLElement) => void] {
4 - const refs = ref<HTMLElement[]>([]); 5 + const refs = ref([]) as Ref<HTMLElement[]>;
5 6
6 onBeforeUpdate(() => { 7 onBeforeUpdate(() => {
7 refs.value = []; 8 refs.value = [];
src/hooks/event/useEventListener.ts
1 import type { Ref } from 'vue'; 1 import type { Ref } from 'vue';
2 -  
3 import { ref, watch, unref } from 'vue'; 2 import { ref, watch, unref } from 'vue';
4 import { useThrottleFn, useDebounceFn } from '@vueuse/core'; 3 import { useThrottleFn, useDebounceFn } from '@vueuse/core';
5 4
6 export type RemoveEventFn = () => void; 5 export type RemoveEventFn = () => void;
7 -  
8 export interface UseEventParams { 6 export interface UseEventParams {
9 el?: Element | Ref<Element | undefined> | Window | any; 7 el?: Element | Ref<Element | undefined> | Window | any;
10 name: string; 8 name: string;
@@ -28,7 +26,7 @@ export function useEventListener({ @@ -28,7 +26,7 @@ export function useEventListener({
28 const isAddRef = ref(false); 26 const isAddRef = ref(false);
29 27
30 if (el) { 28 if (el) {
31 - const element: Ref<Element> = ref(el as Element); 29 + const element = ref(el as Element) as Ref<Element>;
32 30
33 const handler = isDebounce ? useDebounceFn(listener, wait) : useThrottleFn(listener, wait); 31 const handler = isDebounce ? useDebounceFn(listener, wait) : useThrottleFn(listener, wait);
34 const realHandler = wait ? handler : listener; 32 const realHandler = wait ? handler : listener;
src/hooks/web/useECharts.ts
1 import type { EChartsOption } from 'echarts'; 1 import type { EChartsOption } from 'echarts';
2 import type { Ref } from 'vue'; 2 import type { Ref } from 'vue';
3 -  
4 import { useTimeoutFn } from '/@/hooks/core/useTimeout'; 3 import { useTimeoutFn } from '/@/hooks/core/useTimeout';
5 import { tryOnUnmounted } from '@vueuse/core'; 4 import { tryOnUnmounted } from '@vueuse/core';
6 import { unref, nextTick, watch, computed, ref } from 'vue'; 5 import { unref, nextTick, watch, computed, ref } from 'vue';
7 import { useDebounceFn } from '@vueuse/core'; 6 import { useDebounceFn } from '@vueuse/core';
8 import { useEventListener } from '/@/hooks/event/useEventListener'; 7 import { useEventListener } from '/@/hooks/event/useEventListener';
9 import { useBreakpoint } from '/@/hooks/event/useBreakpoint'; 8 import { useBreakpoint } from '/@/hooks/event/useBreakpoint';
10 -  
11 import echarts from '/@/utils/lib/echarts'; 9 import echarts from '/@/utils/lib/echarts';
12 import { useRootSetting } from '/@/hooks/setting/useRootSetting'; 10 import { useRootSetting } from '/@/hooks/setting/useRootSetting';
13 11
@@ -18,19 +16,19 @@ export function useECharts( @@ -18,19 +16,19 @@ export function useECharts(
18 const { getDarkMode } = useRootSetting(); 16 const { getDarkMode } = useRootSetting();
19 let chartInstance: echarts.ECharts | null = null; 17 let chartInstance: echarts.ECharts | null = null;
20 let resizeFn: Fn = resize; 18 let resizeFn: Fn = resize;
21 - const cacheOptions = ref<EChartsOption>({}); 19 + const cacheOptions = ref({}) as Ref<EChartsOption>;
22 let removeResizeFn: Fn = () => {}; 20 let removeResizeFn: Fn = () => {};
23 21
24 resizeFn = useDebounceFn(resize, 200); 22 resizeFn = useDebounceFn(resize, 200);
25 23
26 - const getOptions = computed((): EChartsOption => { 24 + const getOptions = computed(() => {
27 if (getDarkMode.value !== 'dark') { 25 if (getDarkMode.value !== 'dark') {
28 - return cacheOptions.value; 26 + return cacheOptions.value as EChartsOption;
29 } 27 }
30 return { 28 return {
31 backgroundColor: 'transparent', 29 backgroundColor: 'transparent',
32 ...cacheOptions.value, 30 ...cacheOptions.value,
33 - }; 31 + } as EChartsOption;
34 }); 32 });
35 33
36 function initCharts(t = theme) { 34 function initCharts(t = theme) {
src/utils/is.ts
@@ -84,7 +84,7 @@ export function isElement(val: unknown): val is Element { @@ -84,7 +84,7 @@ export function isElement(val: unknown): val is Element {
84 return isObject(val) && !!val.tagName; 84 return isObject(val) && !!val.tagName;
85 } 85 }
86 86
87 -export function isMap(val: unknown): val is Map { 87 +export function isMap(val: unknown): val is Map<any, any> {
88 return is(val, 'Map'); 88 return is(val, 'Map');
89 } 89 }
90 90