Skip to content

Commit

Permalink
style: fix implicitAny true
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangpaopao0609 committed Feb 4, 2025
1 parent 9f67b42 commit 86fb7c9
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 29 deletions.
4 changes: 3 additions & 1 deletion packages/components/date-picker/hooks/useRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function useRange(props: TdDateRangePickerProps) {

const popupVisible = ref(false);
const isHoverCell = ref(false);
const activeIndex = ref(0); // 确定当前选中的输入框序号
const activeIndex = ref<0 | 1>(0); // 确定当前选中的输入框序号
const inputValue = ref(formatDate(props.value, { format: formatRef.value.format })); // 未真正选中前可能不断变更输入框的内容
const isReadOnly = useReadonly();

Expand Down Expand Up @@ -128,6 +128,8 @@ export default function useRange(props: TdDateRangePickerProps) {

// 这里劫持了进一步向 popup 传递的 onVisibleChange 事件,为了保证可以在 Datepicker 中使用 popupProps.onVisibleChange,故此处理
props.popupProps?.onVisibleChange?.(visible, context);
// TODO
// @ts-ignore types only declare onVisibleChange,but not declare on-visible-change
props.popupProps?.['on-visible-change']?.(visible, context);

// 输入框点击不关闭面板
Expand Down
2 changes: 2 additions & 0 deletions packages/components/date-picker/hooks/useSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ export default function useSingle(props: TdDatePickerProps) {
if (disabled.value) return;
// 这里劫持了进一步向 popup 传递的 onVisibleChange 事件,为了保证可以在 Datepicker 中使用 popupProps.onVisibleChange,故此处理
props.popupProps?.onVisibleChange?.(visible, context);
// TODO
// @ts-ignore types only declare onVisibleChange,but not declare on-visible-change
props.popupProps?.['on-visible-change']?.(visible, context);
// 输入框点击不关闭面板
if (context.trigger === 'trigger-element-click') {
Expand Down
1 change: 1 addition & 0 deletions packages/components/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export default defineComponent({
const hasEventOn = (name: string) => {
// _events 因没有被暴露在vue实例接口中,只能把这个规则注释掉
// eslint-disable-next-line dot-notation
// @ts-ignore
const eventFuncs = this['_events']?.[name];
return !!eventFuncs?.length;
};
Expand Down
5 changes: 4 additions & 1 deletion packages/components/dialog/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import TButton, { ButtonProps } from '../button';
import { PopconfirmConfig, DialogConfig, DrawerConfig } from '../config-provider';
import type { ClassName } from '../common';
import type { TdDialogProps } from './type';
import { getPropertyValFromObj } from '../../utils/general';

export interface MixinsConfirmBtn {
theme?: MixinsThemeType;
Expand Down Expand Up @@ -38,8 +39,10 @@ export function useAction(action: BtnAction) {
// 全局配置属性综合
const getDefaultConfirmBtnProps = (options: MixinsConfirmBtn): ButtonProps => {
const { globalConfirm, theme, globalConfirmBtnTheme } = options;
const defaultTheme = omit(globalConfirmBtnTheme, ['info'])?.[theme] || 'primary';
const defaultTheme = getPropertyValFromObj(omit(globalConfirmBtnTheme, ['info']), theme) || 'primary';
let props: ButtonProps = {
// @ts-ignore
// TODO: 这里的类型是有问题的,出在 globalConfirmBtnTheme 上
theme: defaultTheme,
size: options.size,
onClick: (e) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/components/form/form-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,13 @@ export default defineComponent({
.filter((item) => item.result !== true)
.map((item: ErrorListType) => {
Object.keys(item).forEach((key) => {
// @ts-ignore
if (!item.message && errorMessages.value[key]) {
const name = isString(props.label) ? props.label : props.name;
// @ts-ignore
item.message = template(errorMessages.value[key], {
name,
// @ts-ignore
validate: item[key],
});
}
Expand Down
4 changes: 3 additions & 1 deletion packages/components/form/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default defineComponent({
return fields.indexOf(`${name}`) !== -1;
};
const formatValidateResult = <T extends Data>(validateResultList: FormItemValidateResult<T>[]) => {
const result = validateResultList.reduce((r, err) => Object.assign(r || {}, err), {});
const result: Record<string, any> = validateResultList.reduce((r, err) => Object.assign(r || {}, err), {});
Object.keys(result).forEach((key) => {
if (result[key] === true) {
delete result[key];
Expand Down Expand Up @@ -172,6 +172,8 @@ export default defineComponent({
if (!keys.length) return;
const list = children.value
.filter((child) => isFunction(child.setValidateMessage) && keys.includes(`${child.name}`))
// @ts-ignore
// TODO: 😭
.map((child) => child.setValidateMessage(validateMessage[child.name]));
Promise.all(list);
};
Expand Down
23 changes: 16 additions & 7 deletions packages/components/grid/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isNumber } from 'lodash-es';
import { isObject } from 'lodash-es';
import { isArray } from 'lodash-es';

import { TdColProps, TdRowProps } from './type';
import { GutterObject, TdColProps, TdRowProps } from './type';
import { calcSize } from '../../utils/responsive';
import { useListener } from '../hooks/useListener';
import { isServer } from '../utils/dom';
Expand Down Expand Up @@ -52,7 +52,8 @@ export function getRowClasses(name: string, props: TdRowProps) {
* @param currentSize
* @returns
*/
export function calcRowStyle(gutter: TdRowProps['gutter'], currentSize: string) {
// TODO: 看代码,已经没有用到了,是不是可以删除了
export function calcRowStyle(gutter: TdRowProps['gutter'], currentSize: keyof GutterObject) {
const rowStyle = {};
const getMarginStyle = (gutter: number) =>
Object.assign(rowStyle, {
Expand Down Expand Up @@ -80,6 +81,7 @@ export function calcRowStyle(gutter: TdRowProps['gutter'], currentSize: string)
}

if (isObject(gutter[0]) && !isUndefined(gutter[0][currentSize])) {
const a = gutter[0];
getMarginStyle(gutter[0][currentSize]);
}

Expand All @@ -89,24 +91,30 @@ export function calcRowStyle(gutter: TdRowProps['gutter'], currentSize: string)
}
},
isObject: (gutter: TdRowProps['gutter']) => {
// TODO: 好吧,这里明显就不对
// @ts-ignore
if (isObject(gutter) && gutter[currentSize]) {
if (isArray(gutter) && gutter.length) {
// @ts-ignore
// TODO: 你看,这里是数组吧,但又来 currentSize
getMarginStyle(gutter[currentSize][0]);
// @ts-ignore
getRowGapStyle(gutter[currentSize][1]);
} else {
// @ts-ignore
getMarginStyle(gutter[currentSize]);
}
}
},
};

Object.keys(strategyMap).forEach((item) => {
// @ts-ignore
strategyMap[item](gutter);
});

return rowStyle;
}

/**
* 解析Flex
* @param flex
Expand All @@ -129,7 +137,7 @@ export function parseFlex(flex: TdColProps['flex']): string {
* @param currentSize
* @returns
*/
export function calcColPadding(gutter: TdRowProps['gutter'], currentSize: string) {
export function calcColPadding(gutter: TdRowProps['gutter'], currentSize: keyof GutterObject) {
const paddingObj = {};
const getPaddingStyle = (gutter: number) =>
Object.assign(paddingObj, {
Expand All @@ -154,13 +162,14 @@ export function calcColPadding(gutter: TdRowProps['gutter'], currentSize: string
}
},
isObject: (gutter: TdRowProps['gutter']) => {
if (isObject(gutter) && gutter[currentSize]) {
// TODO: 你看,这里就不对的 isObject 在乱用
if (isObject(gutter) && !isArray(gutter) && gutter[currentSize]) {
getPaddingStyle(gutter[currentSize]);
}
},
};

Object.keys(strategyMap).forEach((item) => {
Object.keys(strategyMap).forEach((item: keyof typeof strategyMap) => {
strategyMap[item](gutter);
});

Expand All @@ -174,7 +183,7 @@ export function calcColPadding(gutter: TdRowProps['gutter'], currentSize: string
*/
export function getColClasses(name: string, props: TdColProps) {
const { span, order, offset, push, pull } = props;
const allSizes = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'];
const allSizes = ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'] as const;

const ColSizeClasses = allSizes.reduce((acc, currSize) => {
const sizeProp = props[currSize];
Expand Down
2 changes: 1 addition & 1 deletion packages/components/grid/row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default defineComponent({
const COMPONENT_NAME = usePrefixClass('row');
const rowClasses = computed(() => getRowClasses(COMPONENT_NAME.value, props));

const rowStyle = computed(() => calcRowStyle(props.gutter, size.value));
const rowStyle = computed(() => (props.gutter, size.value));

return () => {
const { tag: TAG } = props;
Expand Down
2 changes: 1 addition & 1 deletion packages/components/hooks/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useIcon() {
let iconContent;
// 传入的是渲染函数
if (isFunction(instance.props[iconType])) {
iconContent = (instance.props as Object)[iconType](h);
iconContent = instance.props[iconType](h);
} else if (instance.slots[iconType]) {
// 插槽slot
iconContent = instance.slots[iconType] && instance.slots[iconType](null)[0];
Expand Down
4 changes: 2 additions & 2 deletions packages/components/hooks/useGlobalIcon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { useConfig } from './useConfig';
import { IconConfig } from '../config-provider/type';

// 从 globalConfig 获取 icon 配置用于覆盖组件内置 icon
export function useGlobalIcon(tdIcon: Object) {
export function useGlobalIcon(tdIcon: object) {
const { globalConfig } = useConfig('icon');

const resultIcon: IconConfig = {};

Object.keys(tdIcon).forEach((key) => {
Object.keys(tdIcon).forEach((key: keyof typeof tdIcon) => {
resultIcon[key] = globalConfig.value?.[key] || tdIcon[key];
});

Expand Down
11 changes: 6 additions & 5 deletions packages/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,23 @@ export default defineComponent({
const inputEventHandler = useInputEventHandler(props, isHover);

const tPlaceholder = computed(() => props.placeholder ?? globalConfig.value.placeholder);
const inputAttrs = computed(() =>
getValidAttrs({
const inputAttrs = computed(() => {
const value = {
autofocus: props.autofocus,
disabled: disabled.value,
readonly: readonly.value,
placeholder: tPlaceholder.value,
name: props.name || undefined,
type: renderType.value,
autocomplete: props.autocomplete ?? (globalConfig.value.autocomplete || undefined),
unselectable: readonly.value ? 'on' : undefined,
unselectable: readonly.value ? 'on' : 'off',
spellcheck: props.spellCheck,
// 不要传给 input 原生元素 maxlength,浏览器默认行为会按照 unicode 进行限制,与 maxLength API 违背
// https://github.com/Tencent/tdesign-vue-next/issues/4413
// 参见: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/maxlength,提到了字符串长度的计算方法,就是 str.length
}),
);
} as const;
return getValidAttrs(value);
});

const wrapClasses = computed(() => [
INPUT_WRAP_CLASS.value,
Expand Down
2 changes: 2 additions & 0 deletions packages/components/loading/directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const createInstance = (el: HTMLElement, binding: DirectiveBinding) => {

if (isObject(binding.value)) {
mapKeys(binding.value, (value, key) => {
// @ts-ignore
// TODO: 😭
options[key] = value;
});
}
Expand Down
13 changes: 3 additions & 10 deletions packages/utils/general.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isFunction, isObject } from 'lodash-es';

const hasOwnProperty = Object.prototype.hasOwnProperty;

export const hasOwn = <T extends object>(val: T, key: string | symbol | number): key is keyof T =>
Expand All @@ -11,16 +13,7 @@ export const getPropertyValFromObj = <T extends object>(

const objectToString: typeof Object.prototype.toString = Object.prototype.toString;
const toTypeString = (value: unknown): string => objectToString.call(value);
export const isArray: typeof Array.isArray = Array.isArray;
export const isMap = (val: unknown): val is Map<any, any> => toTypeString(val) === '[object Map]';
export const isSet = (val: unknown): val is Set<any> => toTypeString(val) === '[object Set]';
export const isDate = (val: unknown): val is Date => toTypeString(val) === '[object Date]';
export const isRegExp = (val: unknown): val is RegExp => toTypeString(val) === '[object RegExp]';
export const isFunction = (val: unknown): val is Function => typeof val === 'function';
export const isString = (val: unknown): val is string => typeof val === 'string';
export const isSymbol = (val: unknown): val is symbol => typeof val === 'symbol';
export const isPlainObject = (val: unknown): val is object => toTypeString(val) === '[object Object]';
export const isObject = (val: unknown): val is object => val !== null && typeof val === 'object';
export const isPlainObject = <T extends object>(val: unknown): val is T => toTypeString(val) === '[object Object]';
export const isPromise = <T = any>(val: unknown): val is Promise<T> => {
return (isObject(val) || isFunction(val)) && isFunction((val as any).then) && isFunction((val as any).catch);
};

0 comments on commit 86fb7c9

Please sign in to comment.