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