Skip to content
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

Unable to compile with Typescript 4.5.4 #179

Open
GSuggitt opened this issue Jan 13, 2022 · 4 comments · May be fixed by #196
Open

Unable to compile with Typescript 4.5.4 #179

GSuggitt opened this issue Jan 13, 2022 · 4 comments · May be fixed by #196

Comments

@GSuggitt
Copy link

I recently upgraded the version of typescript in a react project to version 4.5.4.
When I did this I got an compile error reported in react-dropzone-uploader.
I am using version 2.11.0 of react-dropzone-uploader
In Typescript 4.4 the typing of the catch variable was changed to be "unknown" from "any". As a result the error was reported.
The error I get is:
node_modules/react-dropzone-uploader/dist/Dropzone.tsx:504:44 - error TS2571: Object is of type 'unknown'.
The code in Dropzone.tsx is:

  uploadFile = async (fileWithMeta: IFileWithMeta) => {
    const { getUploadParams } = this.props
    if (!getUploadParams) return
    let params: IUploadParams | null = null
    try {
      params = await getUploadParams(fileWithMeta)
    } catch (e) {
      console.error('Error Upload Params', e.stack)
    }
    if (params === null) return
    const { url, method = 'POST', body, fields = {}, headers = {}, meta: extraMeta = {} } = params
    delete extraMeta.status

The problem is the catch variable "e" is now typed as "unknown" and so it is an error to attempt to access a member of "unknown"

Typescript has introduced an option "useUnknownInCatchVariables" which when set to "false" will allow the code to compile and that is how I am getting around the problem.

A suggestion has been made to me that I need to wrap my call to react-dropzone-uploader in a try-catch to solve my problem.
That will not solve my issue. My issue is I cannot compile my project.
The person making the suggestion seemed to believe that the try-catch in question was in my code and that I should fix my code.

The problem lies in the Dropzone.tsx file of react-dropzone_uploader. And the fix is very easy:

    try {
      params = await getUploadParams(fileWithMeta)
    } catch (e) {
      console.error('Error Upload Params', (e as any).stack)
    }

@beinghaziq
Copy link

Hi, @GSuggitt have you resolved this issue on your end?? I'm getting the same issue and I haven't reached any solution yet other than setting useUnknownInCatchVariables as false in tsconfig file.

@GSuggitt
Copy link
Author

GSuggitt commented Jan 25, 2022 via email

@BHunter2889
Copy link

Is there an update on this? Is this project still even active? This seems like such a simple fix that for such a widely used project it should've been fixed by now... no offense intended, but would like to see an update of any kind.

@prmichaelsen
Copy link

Note that setting useUnknownInCatchVariables to false isn't the real fix. Like @GSuggitt said, the problem is tsx files are published to dist. I wouldn't modify your tsconfig to get around this, since you likely want those errors. For now, I just delete the tsx files manually.

#108 (comment)

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

Successfully merging a pull request may close this issue.

4 participants