Skip to content

TS2322: Type 'string | number | any[] | { value: any; symbol: any; exponent: number; unit: string; }' is not assignable to type 'ReactNode'. #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
greenpau opened this issue Nov 1, 2022 · 6 comments

Comments

@greenpau
Copy link

greenpau commented Nov 1, 2022

After the upgrade to React 18, I started getting the following Typescript errors:

ERROR in src/components/CreateJob/ReviewStep.tsx:102:47
TS2322: Type 'string | number | any[] | { value: any; symbol: any; exponent: number; unit: string; }' is not assignable to type 'ReactNode'.
  Type '{ value: any; symbol: any; exponent: number; unit: string; }' is not assignable to type 'ReactNode'.
    100 |               header: 'File Size',
    101 |               cell: (item) => {
  > 102 |                 return <Box textAlign="right">{filesize(item.size, { base: 2, standard: 'jedec' }) || '-'}</Box>;
        |                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    103 |               },
    104 |             },
    105 |           ]}

ERROR in src/components/FileUpload/FileUploadTable.tsx:227:39
TS2322: Type 'string | number | any[] | { value: any; symbol: any; exponent: number; unit: string; }' is not assignable to type 'ReactNode'.
    225 |       header: 'Size',
    226 |       cell: (item) => {
  > 227 |         return <Box textAlign="right">{filesize(item.size, { base: 2, standard: 'jedec' }) || '-'}</Box>;
        |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    228 |       },
    229 |       sortingField: 'size',
    230 |     },

ERROR in src/components/FileUpload/StagedFileList.tsx:48:43
TS2322: Type 'string | number | any[] | { value: any; symbol: any; exponent: number; unit: string; }' is not assignable to type 'ReactNode'.
  Type '{ value: any; symbol: any; exponent: number; unit: string; }' is not assignable to type 'ReactNode'.
    46 |           header: 'File Size',
    47 |           cell: (item) => {
  > 48 |             return <Box textAlign="right">{filesize(item.file.size, { base: 2, standard: 'jedec' }) || '-'}</Box>;
       |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    49 |           },
    50 |         },
    51 |         {
@avoidwork
Copy link
Owner

avoidwork commented Nov 3, 2022

That file is generated; tsc bug? Considering this issue is entirely imaginary, what is the suggested problem/solution?

@greenpau
Copy link
Author

greenpau commented Nov 3, 2022

That file is generated; tsc bug?

Yes. There is some difference between React 17 and React 18 handling of the filesize module.

@avoidwork
Copy link
Owner

does the type file for earlier versions work? the persons chose a diff structure than tsc generates.

@greenpau
Copy link
Author

greenpau commented Nov 4, 2022

@avoidwork , yes. I was using filesize with react 17 and things worked just fine.

@avoidwork
Copy link
Owner

@greenpau are you using @types/react 18.0.0? from what i'm reading this has nothing to do with filesize and simply relates to the optional object output.

@greenpau greenpau closed this as completed Nov 8, 2022
@felixhoffmnn
Copy link

felixhoffmnn commented Jun 12, 2023

I ran into the same problem. The main problem is that the return type from the filesize() function can be of the following types:

string | number | any[] | {
    value: any;
    symbol: any;
    exponent: number;
    unit: string;
};

If you want to use the result of the filesize() function inside a JSX element, the expected type is a string, integer, or iterable, which does not quite match the defined type of object. @avoidwork is it beneficial to combine these different types, or could we split them into separate functions to prevent the mismatch with ReactNode?

I was able to fix the type error by just parsing the result to a string (like filesize().toString()). But that solution is not as pretty as I would like it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants