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

View File

@ -79,7 +79,7 @@
if (!isArray(result)) { if (!isArray(result)) {
result = get(result, props.resultField); result = get(result, props.resultField);
} }
treeData.value = (result as Recordable<any>[]) || []; treeData.value = (result as (Recordable & { key: string | number })[]) || [];
isFirstLoaded.value = true; isFirstLoaded.value = true;
emit('options-change', treeData.value); 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 type { ComponentType } from '../../types/componentType';
import { componentMap } from '/@/components/Table/src/componentMap'; import { componentMap } from '/@/components/Table/src/componentMap';
@ -13,7 +13,7 @@ export interface ComponentProps {
getPopupContainer?: Fn; getPopupContainer?: Fn;
} }
export const CellComponent: FunctionalComponent = ( export const CellComponent = (
{ {
component = 'Input', component = 'Input',
rule = true, rule = true,

View File

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

View File

@ -1,9 +1,9 @@
import type { VNode, FunctionalComponent } from 'vue'; import type { VNode } from 'vue';
import { h } from 'vue'; import { h } from 'vue';
import { isString } from 'lodash-es'; import { isString } from 'lodash-es';
import Icon from '@/components/Icon/Icon.vue'; 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 (!icon) return null;
if (isString(icon)) { if (isString(icon)) {
return h(Icon, { icon, class: 'mr-1' }); return h(Icon, { icon, class: 'mr-1' });

View File

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

View File

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

View File

@ -13,7 +13,7 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, PropType, computed } from 'vue'; 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 { useDesign } from '/@/hooks/web/useDesign';
import { useI18n } from '/@/hooks/web/useI18n'; import { useI18n } from '/@/hooks/web/useI18n';
import { baseHandler } from '../handler'; import { baseHandler } from '../handler';
@ -43,9 +43,11 @@
const getBindValue = computed(() => { const getBindValue = computed(() => {
return props.def ? { checked: props.def } : {}; 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 { return {
prefixCls, prefixCls,
t, t,

View File

@ -17,7 +17,7 @@
import { defineComponent, ref, unref, h } from 'vue'; import { defineComponent, ref, unref, h } from 'vue';
import { CodeEditor, JsonPreview, MODE } from '/@/components/CodeEditor'; import { CodeEditor, JsonPreview, MODE } from '/@/components/CodeEditor';
import { PageWrapper } from '/@/components/Page'; 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 = 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"}]}'; '{"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 modeValue = ref<MODE>(MODE.JSON);
const value = ref(jsonData); const value = ref(jsonData);
function handleModeChange(e: ChangeEvent) { const handleModeChange: RadioGroupProps['onChange'] = (e) => {
const mode = e.target.value; const mode = e.target.value;
if (mode === MODE.JSON) { if (mode === MODE.JSON) {
value.value = jsonData; value.value = jsonData;
@ -79,7 +79,7 @@
value.value = jsData; value.value = jsData;
return; return;
} }
} };
function showData() { function showData() {
if (unref(modeValue) === 'application/json') { if (unref(modeValue) === 'application/json') {

View File

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

View File

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

2
types/index.d.ts vendored
View File

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