Repository: ant-design/ant-design-mobile
Pull request #6262 (2023-07-19 08:33:16)

chore: type enhance
比 #6259 好些得写法可以不用 as 了

 `const props = child.props` 与顶部的 `const props = mergeProps(defaultProps, p)`  命名感觉有点混淆 ，然后改成 `childProps` 了


github-actions[bot]: PR preview has been successfully built and deployed to https://antd-mobile-preview-pr-6262.surge.sh

Patch:
diff --git a/src/components/steps/steps.tsx b/src/components/steps/steps.tsx
index 224c3de33..944c3ef5c 100644
--- a/src/components/steps/steps.tsx
+++ b/src/components/steps/steps.tsx
@@ -36,24 +36,24 @@ export const Steps: FC<StepsProps> = p => {
     props,
     <div className={classString}>
       {React.Children.map(props.children, (child, index) => {
-        if (!React.isValidElement(child)) {
+        if (!React.isValidElement<StepProps>(child)) {
           return child
         }
-        const props = child.props as StepProps
-        let status = props.status || 'wait'
+        const childProps = child.props
+        let status = childProps.status || 'wait'
 
         if (index < current) {
-          status = props.status || 'finish'
+          status = childProps.status || 'finish'
         } else if (index === current) {
-          status = props.status || 'process'
+          status = childProps.status || 'process'
         }
 
-        const icon = props.icon ?? defaultIcon
+        const icon = childProps.icon ?? defaultIcon
 
         return React.cloneElement(child, {
           status,
           icon,
-        } as StepProps)
+        })
       })}
     </div>
   )
diff --git a/src/components/swipe-action/swipe-action.tsx b/src/components/swipe-action/swipe-action.tsx
index 75d39e225..dd912649e 100644
--- a/src/components/swipe-action/swipe-action.tsx
+++ b/src/components/swipe-action/swipe-action.tsx
@@ -19,9 +19,11 @@ import {
 
 const classPrefix = `adm-swipe-action`
 
+type SideType = 'left' | 'right'
+
 export type SwipeActionRef = {
   close: () => void
-  show: (side?: 'left' | 'right') => void
+  show: (side?: SideType) => void
 }
 
 type ActionColor =
@@ -47,7 +49,7 @@ export type SwipeActionProps = {
   closeOnAction?: boolean
   children: ReactNode
   stopPropagation?: PropagationEvent[]
-  onActionsReveal?: (side: 'left' | 'right') => void
+  onActionsReveal?: (side: SideType) => void
 } & NativeProps<'--background'>
 
 const defaultProps = {
@@ -157,7 +159,7 @@ export const SwipeAction = forwardRef<SwipeActionRef, SwipeActionProps>(
     }
 
     useImperativeHandle(ref, () => ({
-      show: (side: 'left' | 'right' = 'right') => {
+      show: (side: SideType = 'right') => {
         if (side === 'right') {
           api.start({
             x: -getRightWidth(),
diff --git a/src/components/text-area/text-area.tsx b/src/components/text-area/text-area.tsx
index dcc3e47df..b799f4001 100644
--- a/src/components/text-area/text-area.tsx
+++ b/src/components/text-area/text-area.tsx
@@ -135,13 +135,23 @@ export const TextArea = forwardRef<TextAreaRef, TextAreaProps>(
       )
     }
 
+    let rows = props.rows
+    if (typeof autoSize === 'object') {
+      if (autoSize.maxRows && rows > autoSize.maxRows) {
+        rows = autoSize.maxRows
+      }
+      if (autoSize.minRows && rows < autoSize.minRows) {
+        rows = autoSize.minRows
+      }
+    }
+
     return withNativeProps(
       props,
       <div className={classPrefix}>
         <textarea
           ref={nativeTextAreaRef}
           className={`${classPrefix}-element`}
-          rows={props.rows}
+          rows={rows}
           value={value}
           placeholder={props.placeholder}
           onChange={e => {
@@ -180,7 +190,7 @@ export const TextArea = forwardRef<TextAreaRef, TextAreaProps>(
             ref={hiddenTextAreaRef}
             className={`${classPrefix}-element ${classPrefix}-element-hidden`}
             value={value}
-            rows={props.rows}
+            rows={rows}
             aria-hidden
             readOnly
           />


Test patch:
diff --git a/src/components/text-area/tests/text-area.test.tsx b/src/components/text-area/tests/text-area.test.tsx
index 6f3d4dfc8..d5aba7ff6 100644
--- a/src/components/text-area/tests/text-area.test.tsx
+++ b/src/components/text-area/tests/text-area.test.tsx
@@ -130,4 +130,16 @@ describe('TextArea', () => {
     expect(textarea).toHaveAttribute('rows', '1')
     expect(hiddenTextarea).toHaveAttribute('rows', '1')
   })
+
+  test('rows should be the minRows when rows < minRows', () => {
+    const { getByRole } = render(<TextArea autoSize={{ minRows: 3 }} />)
+    const textarea = getByRole('textbox')
+    expect(textarea).toHaveAttribute('rows', '3')
+  })
+
+  test('rows should be the maxRows when rows > maxRows', () => {
+    const { getByRole } = render(<TextArea autoSize={{ maxRows: 1 }} />)
+    const textarea = getByRole('textbox')
+    expect(textarea).toHaveAttribute('rows', '1')
+  })
 })