chore: fix type:check error (#3126)

* chore: Fix ts type error

* chore: fix type:check error
This commit is contained in:
bowen 2023-10-10 21:06:16 +08:00 committed by GitHub
parent b43d3069e1
commit 30b3ee5c89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 48 additions and 34 deletions

View File

@ -26,7 +26,7 @@ type NonNullable<T> = T extends null | undefined ? never : T;
/**
*
*/
type Recordable<T> = Record<string, T>;
type Recordable<T = any> = Record<string, T>;
/**
*

View File

@ -43,7 +43,7 @@
import type { Ref } from 'vue';
import { defineComponent, reactive, ref, computed, unref, onMounted, watch, nextTick } from 'vue';
import { Form, Row } from 'ant-design-vue';
import { Form, Row, type FormProps as AntFormProps } from 'ant-design-vue';
import FormItem from './components/FormItem.vue';
import FormAction from './components/FormAction.vue';
@ -112,7 +112,9 @@
};
});
const getBindValue = computed(() => ({ ...attrs, ...props, ...unref(getProps) }));
const getBindValue = computed(
() => ({ ...attrs, ...props, ...unref(getProps) }) as AntFormProps,
);
const getSchema = computed((): FormSchema[] => {
const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any);
@ -303,7 +305,10 @@
formActionType: formActionType as any,
setFormModel,
getFormClass,
getFormActionBindProps: computed(() => ({ ...getProps.value, ...advanceState })),
getFormActionBindProps: computed(
() =>
({ ...getProps.value, ...advanceState }) as InstanceType<typeof FormAction>['$props'],
),
fieldsIsAdvancedMap,
...formActionType,
};

View File

@ -79,7 +79,7 @@
if (!isArray(result)) {
result = get(result, props.resultField);
}
treeData.value = (result as Recordable<any>[]) || [];
treeData.value = (result as (Recordable & { key: string | number })[]) || [];
isFirstLoaded.value = true;
emit('options-change', treeData.value);
}

View File

@ -1,4 +1,4 @@
import type { FunctionalComponent, defineComponent } from 'vue';
import type { defineComponent } from 'vue';
import type { ComponentType } from '../../types/componentType';
import { componentMap } from '/@/components/Table/src/componentMap';
@ -13,7 +13,7 @@ export interface ComponentProps {
getPopupContainer?: Fn;
}
export const CellComponent: FunctionalComponent = (
export const CellComponent = (
{
component = 'Input',
rule = true,

View File

@ -23,8 +23,8 @@ export function createSimpleTransition(name: string, origin = 'top center 0', mo
},
},
setup(props, { slots, attrs }) {
const onBeforeEnter = (el: HTMLElement) => {
el.style.transformOrigin = props.origin;
const onBeforeEnter = (el: Element) => {
(el as HTMLElement).style.transformOrigin = props.origin;
};
return () => {

View File

@ -1,9 +1,9 @@
import type { VNode, FunctionalComponent } from 'vue';
import type { VNode } from 'vue';
import { h } from 'vue';
import { isString } from 'lodash-es';
import Icon from '@/components/Icon/Icon.vue';
export const TreeIcon: FunctionalComponent = ({ icon }: { icon: VNode | string }) => {
export const TreeIcon = ({ icon }: { icon: VNode | string }) => {
if (!icon) return null;
if (isString(icon)) {
return h(Icon, { icon, class: 'mr-1' });

View File

@ -34,7 +34,14 @@
</template>
<script lang="ts" setup>
import { type PropType, computed, ref, watch, useSlots } from 'vue';
import { Dropdown, Menu, MenuItem, MenuDivider, InputSearch } from 'ant-design-vue';
import {
Dropdown,
Menu,
MenuItem,
MenuDivider,
InputSearch,
type MenuProps,
} from 'ant-design-vue';
import Icon from '@/components/Icon/Icon.vue';
import { BasicTitle } from '/@/components/Basic';
import { useI18n } from '/@/hooks/web/useI18n';
@ -122,8 +129,7 @@
: defaultToolbarList;
});
function handleMenuClick(e: { key: ToolbarEnum }) {
const { key } = e;
const handleMenuClick: MenuProps['onClick'] = ({ key }) => {
switch (key) {
case ToolbarEnum.SELECT_ALL:
props.checkAll?.(true);
@ -144,7 +150,7 @@
emit('strictly-change', true);
break;
}
}
};
function emitChange(value?: string): void {
emit('search', value);

View File

@ -14,7 +14,7 @@
<script lang="ts">
import { defineComponent, PropType, computed } from 'vue';
import { Select } from 'ant-design-vue';
import { Select, type SelectProps } from 'ant-design-vue';
import { useDesign } from '/@/hooks/web/useDesign';
import { baseHandler } from '../handler';
import { HandlerEnum } from '../enum';
@ -49,9 +49,10 @@
return props.def ? { value: props.def, defaultValue: props.initValue || props.def } : {};
});
function handleChange(e: ChangeEvent) {
props.event && baseHandler(props.event, e);
}
const handleChange: SelectProps['onChange'] = (val) => {
props.event && baseHandler(props.event, val);
};
return {
prefixCls,
handleChange,

View File

@ -13,7 +13,7 @@
<script lang="ts">
import { defineComponent, PropType, computed } from 'vue';
import { Switch } from 'ant-design-vue';
import { Switch, type SwitchProps } from 'ant-design-vue';
import { useDesign } from '/@/hooks/web/useDesign';
import { useI18n } from '/@/hooks/web/useI18n';
import { baseHandler } from '../handler';
@ -43,9 +43,11 @@
const getBindValue = computed(() => {
return props.def ? { checked: props.def } : {};
});
function handleChange(e: ChangeEvent) {
props.event && baseHandler(props.event, e);
}
const handleChange: SwitchProps['onChange'] = (val) => {
props.event && baseHandler(props.event, val);
};
return {
prefixCls,
t,

View File

@ -17,7 +17,7 @@
import { defineComponent, ref, unref, h } from 'vue';
import { CodeEditor, JsonPreview, MODE } from '/@/components/CodeEditor';
import { PageWrapper } from '/@/components/Page';
import { Radio, Space, Modal } from 'ant-design-vue';
import { Radio, Space, Modal, type RadioGroupProps } from 'ant-design-vue';
const jsonData =
'{"name":"BeJson","url":"http://www.xxx.com","page":88,"isNonProfit":true,"address":{"street":"科技园路.","city":"江苏苏州","country":"中国"},"links":[{"name":"Google","url":"http://www.xxx.com"},{"name":"Baidu","url":"http://www.xxx.com"},{"name":"SoSo","url":"http://www.xxx.com"}]}';
@ -65,7 +65,7 @@
const modeValue = ref<MODE>(MODE.JSON);
const value = ref(jsonData);
function handleModeChange(e: ChangeEvent) {
const handleModeChange: RadioGroupProps['onChange'] = (e) => {
const mode = e.target.value;
if (mode === MODE.JSON) {
value.value = jsonData;
@ -79,7 +79,7 @@
value.value = jsData;
return;
}
}
};
function showData() {
if (unref(modeValue) === 'application/json') {

View File

@ -66,25 +66,25 @@
import { optionsListApi } from '/@/api/demo/select';
import { useDebounceFn } from '@vueuse/core';
import { treeOptionsListApi } from '/@/api/demo/tree';
import { Select } from 'ant-design-vue';
import { Select, type SelectProps } from 'ant-design-vue';
import { cloneDeep } from 'lodash-es';
import { areaRecord } from '/@/api/demo/cascader';
import { uploadApi } from '/@/api/sys/upload';
const valueSelectA = ref<string[]>([]);
const valueSelectB = ref<string[]>([]);
const options = ref<Recordable[]>([]);
const options = ref<Required<SelectProps>['options']>([]);
for (let i = 1; i < 10; i++) options.value.push({ label: '选项' + i, value: `${i}` });
const optionsA = computed(() => {
return cloneDeep(unref(options)).map((op) => {
op.disabled = unref(valueSelectB).indexOf(op.value) !== -1;
op.disabled = unref(valueSelectB).indexOf(op.value as string) !== -1;
return op;
});
});
const optionsB = computed(() => {
return cloneDeep(unref(options)).map((op) => {
op.disabled = unref(valueSelectA).indexOf(op.value) !== -1;
op.disabled = unref(valueSelectA).indexOf(op.value as string) !== -1;
return op;
});
});
@ -705,7 +705,7 @@
const check = ref(null);
const { createMessage } = useMessage();
const keyword = ref<string>('');
const searchParams = computed<Recordable>(() => {
const searchParams = computed<Recordable<string>>(() => {
return { keyword: unref(keyword) };
});

View File

@ -20,7 +20,7 @@
</BasicTable>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
import { defineComponent, ref, unref } from 'vue';
import { BasicTable, useTable } from '/@/components/Table';
import { getBasicColumns, getFormConfig } from './tableData';
import { Alert } from 'ant-design-vue';
@ -43,7 +43,7 @@
rowKey: 'id',
rowSelection: {
type: 'checkbox',
selectedRowKeys: checkedKeys,
selectedRowKeys: unref(checkedKeys),
onSelect: onSelect,
onSelectAll: onSelectAll,
},

2
types/index.d.ts vendored
View File

@ -14,7 +14,7 @@ declare type LabelValueOptions = {
[key: string]: string | number | boolean;
}[];
declare type EmitType = (event: string, ...args: any[]) => void;
declare type EmitType = ReturnType<typeof defineEmits>;
declare type TargetContext = '_self' | '_blank';