Skip to content

Commit

Permalink
chore: fix type:check error (#3126)
Browse files Browse the repository at this point in the history
* chore: Fix ts type error

* chore: fix type:check error
  • Loading branch information
jiaowoxiaobala committed Oct 10, 2023
1 parent b43d306 commit 30b3ee5
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 34 deletions.
2 changes: 1 addition & 1 deletion packages/types/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

/**
* 字符串类型对象(只读)
Expand Down
11 changes: 8 additions & 3 deletions src/components/Form/src/BasicForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/src/components/ApiTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Table/src/components/editable/CellComponent.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -13,7 +13,7 @@ export interface ComponentProps {
getPopupContainer?: Fn;
}

export const CellComponent: FunctionalComponent = (
export const CellComponent = (
{
component = 'Input',
rule = true,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Transition/src/CreateTransition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Tree/src/TreeIcon.ts
Original file line number Diff line number Diff line change
@@ -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' });
Expand Down
14 changes: 10 additions & 4 deletions src/components/Tree/src/components/TreeHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand All @@ -144,7 +150,7 @@
emit('strictly-change', true);
break;
}
}
};
function emitChange(value?: string): void {
emit('search', value);
Expand Down
9 changes: 5 additions & 4 deletions src/layouts/default/setting/components/SelectItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions src/layouts/default/setting/components/SwitchItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/views/demo/editor/json/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]}';
Expand Down Expand Up @@ -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;
Expand All @@ -79,7 +79,7 @@
value.value = jsData;
return;
}
}
};
function showData() {
if (unref(modeValue) === 'application/json') {
Expand Down
10 changes: 5 additions & 5 deletions src/views/demo/form/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
Expand Down Expand Up @@ -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) };
});
Expand Down
4 changes: 2 additions & 2 deletions src/views/demo/table/FormTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -43,7 +43,7 @@
rowKey: 'id',
rowSelection: {
type: 'checkbox',
selectedRowKeys: checkedKeys,
selectedRowKeys: unref(checkedKeys),
onSelect: onSelect,
onSelectAll: onSelectAll,
},
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down

0 comments on commit 30b3ee5

Please sign in to comment.