浏览代码

fix: ts check error of upload/witFied/fields in strict mode

pointhalo 3 年之前
父节点
当前提交
2f70e0bbc2

+ 2 - 1
packages/semi-foundation/tsconfig.json

@@ -18,7 +18,8 @@
         "strictNullChecks": false,
         "esModuleInterop": true,
         "skipLibCheck": true,
-        "declaration": true
+        "declaration": true,
+        "strict": true
     },
     "include": ["**/*.ts"],
     "exclude": ["node_modules"]

+ 2 - 2
packages/semi-ui/form/_story/form.stories.tsx

@@ -112,8 +112,8 @@ const Fields: FunctionComponent<FormFCChild> = ({ formState, values, formApi })
             label="是否独占资源(Radio)"
             rules={[{ type: 'boolean' }, { required: true, message: '必须选择是否独占 ' }]}
         >
-            <Form.Radio value={true}>是</Form.Radio>
-            <Form.Radio value={false}>否</Form.Radio>
+            <Form.Radio value={1}>是</Form.Radio>
+            <Form.Radio value={0}>否</Form.Radio>
         </Form.RadioGroup>
         <Form.Checkbox field='abc' noLabel>
             我已阅读并清楚相关规定(Checkbox)

+ 1 - 1
packages/semi-ui/form/hoc/withField.tsx

@@ -30,7 +30,7 @@ function withField<
     T extends Subtract<React.ComponentProps<C>, CommonexcludeType> & CommonFieldProps,
     R extends React.ComponentType<T>
 >(Component: C, opts?: WithFieldOption): R {
-    let SemiField = (props: any, ref: React.MutableRefObject<any>) => {
+    let SemiField = (props: any, ref: React.MutableRefObject<any> | ((instance: any) => void)) => {
         let {
             // condition,
             field,

+ 1 - 0
packages/semi-ui/treeSelect/index.tsx

@@ -1166,6 +1166,7 @@ class TreeSelect extends BaseComponent<TreeSelectProps, TreeSelectState> {
                         itemSize={virtualize.itemSize}
                         height={height}
                         width={width}
+                        // @ts-ignore avoid strict check of itemKey
                         itemKey={this.itemKey as ListItemKeySelector<TreeNodeData>}
                         itemData={flattenNodes as any}
                         className={`${prefixTree}-virtual-list`}

+ 2 - 1
packages/semi-ui/tsconfig.json

@@ -25,7 +25,8 @@
         "esModuleInterop": true,
         "skipLibCheck": true,
         "declaration": true,
-        "strictNullChecks": false
+        "strictNullChecks": false,
+        "strict": true
     },
     "include": ["**/*.tsx", "**/*.ts"],
     "exclude": ["node_modules", "packages/rollup-plugin-semi-svg"]

+ 8 - 1
packages/semi-ui/upload/index.tsx

@@ -193,7 +193,14 @@ class Upload extends BaseComponent<UploadProps, UploadState> {
         this.replaceInputRef = React.createRef<HTMLInputElement>();
     }
 
-    static getDerivedStateFromProps(props: UploadProps): Partial<UploadState> | null {
+    /**
+     * Notes: 
+     *   The input parameter and return value here do not declare the type, otherwise tsc may report an error in form/fields.tsx when wrap after withField
+     *   `The types of the parameters "props" and "nextProps" are incompatible.
+           The attribute "action" is missing in the type "Readonly<any>", but it is required in the type "UploadProps".`
+     *   which seems to be a bug, remove props type declare here
+     */
+    static getDerivedStateFromProps(props) {
         const { fileList } = props;
         if ('fileList' in props) {
             return {