Skip to content

Commit

Permalink
chore: Fix ts type error (#3112)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaowoxiaobala authored Oct 9, 2023
1 parent ae09d3c commit 8289332
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
15 changes: 10 additions & 5 deletions src/components/Form/src/BasicForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,19 @@
const getSchema = computed((): FormSchema[] => {
const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any);
for (const schema of schemas) {
const { defaultValue, component, componentProps,isHandleDateDefaultValue = true } = schema;
const {
defaultValue,
component,
componentProps,
isHandleDateDefaultValue = true,
} = schema;
// handle date type
if (isHandleDateDefaultValue && defaultValue && dateItemType.includes(component)) {
const valueFormat =componentProps ? componentProps['valueFormat'] : null;
const valueFormat = componentProps ? componentProps['valueFormat'] : null;
if (!Array.isArray(defaultValue)) {
schema.defaultValue = valueFormat
? dateUtil(defaultValue).format(valueFormat)
: dateUtil(defaultValue);
schema.defaultValue = valueFormat
? dateUtil(defaultValue).format(valueFormat)
: dateUtil(defaultValue);
} else {
const def: any[] = [];
defaultValue.forEach((item) => {
Expand Down
8 changes: 4 additions & 4 deletions src/components/Form/src/hooks/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ export function useForm(props?: Props): UseFormReturnType {
return unref(formRef)?.getFieldsValue() as T;
},

setFieldsValue: async <T>(values: T) => {
setFieldsValue: async <T extends Recordable<any>>(values: T) => {
const form = await getForm();
form.setFieldsValue<T>(values);
form.setFieldsValue(values);
},

appendSchemaByField: async (
schema: FormSchema | FormSchema[],
prefixField: string | undefined,
first: boolean,
first?: boolean,
) => {
const form = await getForm();
form.appendSchemaByField(schema, prefixField, first);
Expand All @@ -107,7 +107,7 @@ export function useForm(props?: Props): UseFormReturnType {
return form.submit();
},

validate: async (nameList?: NamePath[]): Promise<Recordable> => {
validate: async (nameList?: NamePath[] | false): Promise<Recordable> => {
const form = await getForm();
return form.validate(nameList);
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/Scrollbar/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export function renderThumbStyle({ move, size, bar }) {
return style;
}

function extend<T, K>(to: T, _from: K): T & K {
function extend<T extends object, K extends object>(to: T, _from: K): T & K {
return Object.assign(to, _from);
}

export function toObject<T>(arr: Array<T>): Recordable<T> {
export function toObject<T extends object>(arr: Array<T>): Recordable<T> {
const res = {};
for (let i = 0; i < arr.length; i++) {
if (arr[i]) {
Expand Down
6 changes: 4 additions & 2 deletions src/logics/mitt/routeChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import { mitt } from '/@/utils/mitt';
import type { RouteLocationNormalized } from 'vue-router';
import { getRawRoute } from '/@/utils';

const emitter = mitt();

const key = Symbol();

const emitter = mitt<{
[key]: RouteLocationNormalized;
}>();

let lastChangeTab: RouteLocationNormalized;

export function setRouteChange(lastChangeRoute: RouteLocationNormalized) {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/bem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ function genBem(name: string, mods?: Mods): string {
return ` ${name}--${mods}`;
}

// ArrayConstructor.isArray(arg: any): arg is any[]
if (Array.isArray(mods)) {
return mods.reduce<string>((ret, item) => ret + genBem(name, item), '');
return (mods as Mod[]).reduce<string>((ret, item) => ret + genBem(name, item), '');
}

return Object.keys(mods).reduce((ret, key) => ret + (mods[key] ? genBem(name, key) : ''), '');
Expand Down

0 comments on commit 8289332

Please sign in to comment.