Skip to content

Commit 809766f

Browse files
committed
chore: ts type enhance
1 parent 7db014e commit 809766f

File tree

5 files changed

+20
-21
lines changed

5 files changed

+20
-21
lines changed

src/calendar/CalendarTemplate.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useState, useContext, useMemo, forwardRef } from 'react';
22
import { CloseIcon } from 'tdesign-icons-react';
33
import parseTNode from '../_util/parseTNode';
4-
import Button from '../button';
4+
import { Button, ButtonProps } from '../button';
55
import { TDateType, TCalendarValue } from './type';
66
import { usePrefixClass } from '../hooks/useClass';
77
import useDefaultProps from '../hooks/useDefaultProps';
@@ -229,16 +229,13 @@ const CalendarTemplate = forwardRef<HTMLDivElement, CalendarProps>((_props, ref)
229229
);
230230
};
231231

232-
const renderConfirmBtn = (): any => {
233-
if (confirmBtn && typeof confirmBtn !== 'object') {
234-
return confirmBtn;
235-
}
236-
if (confirmBtn && Array.isArray(confirmBtn)) {
237-
return confirmBtn;
238-
}
239-
if (confirmBtn && typeof confirmBtn === 'object') {
240-
return <Button block theme="primary" {...(confirmBtn as any)} onClick={handleConfirm} />;
232+
const renderConfirmBtn = () => {
233+
if (!confirmBtn) return;
234+
235+
if (typeof confirmBtn === 'object') {
236+
return <Button block theme="primary" {...(confirmBtn as ButtonProps)} onClick={handleConfirm} />;
241237
}
238+
return parseTNode(confirmBtn);
242239
};
243240

244241
const className = useMemo(

src/checkbox/CheckboxGroup.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const CheckboxGroup: FC<CheckboxGroupProps> = (props) => {
4747
onChange,
4848
} = useDefaultProps(props, checkboxGroupDefaultProps);
4949

50-
const internalOptions: any[] =
50+
const internalOptions =
5151
Array.isArray(options) && options.length > 0
5252
? options
5353
: React.Children.map(children, (child) => (child as ReactElement).props);
@@ -146,7 +146,7 @@ const CheckboxGroup: FC<CheckboxGroupProps> = (props) => {
146146
const vs = item as number | string;
147147
return (
148148
<Checkbox key={vs} label={vs} value={vs}>
149-
{item as never}
149+
{vs}
150150
</Checkbox>
151151
);
152152
}

src/message/Message.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import useMessageCssTransition from './hooks/useMessageCssTransition';
1010
import useDefaultProps from '../hooks/useDefaultProps';
1111
import { usePrefixClass } from '../hooks/useClass';
1212

13-
import type { StyledProps } from '../common';
13+
import type { StyledProps, TNode } from '../common';
1414
import parseTNode from '../_util/parseTNode';
1515
import { convertUnit } from '../_util/convertUnit';
1616
import { messageDefaultProps } from './defaultProps';
@@ -246,12 +246,15 @@ const Message: React.FC<MessageProps> = (originProps) => {
246246
onCloseBtnClick?.(e);
247247
};
248248

249-
const closeButton =
250-
closeBtn === true ? (
249+
const renderCloseBtn = () => {
250+
if (!closeBtn) return;
251+
252+
return closeBtn === true ? (
251253
<Icon className={`${name}--close-btn`} name="close" size={22} onClick={clickCloseButton} />
252254
) : (
253-
closeBtn
255+
parseTNode(closeBtn as string | TNode)
254256
);
257+
};
255258

256259
return (
257260
<CSSTransition in={messageVisible} appear {...cssTransitionState.props} unmountOnExit>
@@ -276,7 +279,7 @@ const Message: React.FC<MessageProps> = (originProps) => {
276279
{getLinkContent()}
277280
</div>
278281
)}
279-
{parseTNode(closeButton as any)}
282+
{renderCloseBtn()}
280283
</div>
281284
</CSSTransition>
282285
);

src/message/style/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
// eslint-disable-next-line import/no-relative-packages
21
import '../../_common/style/mobile/components/message/v2/_index.less';

src/picker/PickerView.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import useConfig from '../hooks/useConfig';
44
import useDefault from '../_util/useDefault';
55
import withNativeProps, { NativeProps } from '../_util/withNativeProps';
66
import PickerContext from './picker-context';
7-
import { TdPickerProps, PickerValue } from './type';
7+
import { TdPickerProps, PickerValue, TdPickerItemProps } from './type';
88

99
export const getPickerViewDefaultValue = (defaultValue: Array<PickerValue>, children: React.ReactNode) => {
1010
const result = (defaultValue || []).slice(0);
11-
React.Children.forEach(children, (child, index) => {
11+
React.Children.forEach(children, (child: React.ReactElement<TdPickerItemProps>, index) => {
1212
if (React.isValidElement(child) && isUndefined(result[index])) {
13-
const childOptions = (child.props as any).options || [];
13+
const childOptions = child.props.options || [];
1414
const optionsCount = childOptions.length;
1515
const optionsIndex = Math.max(0, optionsCount <= 2 ? optionsCount - 1 : 2);
1616
result[index] = childOptions[optionsIndex]?.value;

0 commit comments

Comments
 (0)