-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Typescript 4.9.4 compatibility issue with catch(err) in Storage module #10824
Comments
Hi there, the other one is more complicated. This one, however, is really in support of Typescript 4, so please correct me if I have something wrong here. The issue is described HERE but what I don't understand is why this hasn't been an issue before. You can work around this by changing tsconfig.json to this:
but as I understand it, the better long-term solution is to be explicit about your catches either by specifying any:
or perhaps by leaving it unknown then testing the type. My gut feel is it's less intrusive to use I think this is simpler to fix which is why I made it a separate issue. I will look for other instances where this is the case. Because I ran into the problem in #10828 maybe I can submit a P.R. but I'm not too familiar with this project and don't want to make a mistake. |
You asked about my project environment - sorry I forgot to answer. I'm building something using React, Typescript 4.94, and bootstrap. As usual, all those pieces bring in their own dependencies. For the most part, Yarn does a pretty good job of managing that. Since I'm using amplify-js I really don't need to bring in my own client-s3, and if I don't explicitly declare that as a dependency, it comes in as a sub-dependency at version 3.6.1. I'm not sure if that will cause conflicts with my other dependencies or not, but it always makes me nervous to use old dependencies in a brand new project. That makes me try to upgrade everything to latest, and that usually gets me into trouble! In this case, though, I thought I would try to leave everything as-is and just use amplify storage 5.0.8 and see what happens. I do want to use the most recent Typescript, though - Typescript gets better with every release. Not to wax too philosophically but I try to write issues for which I can provide a standalone example, but extricating those examples out of a project is not always easy. But I will give it a try if you can't replicate this one. My advice though is to try to just build something - anything - using Typescript 4.9.4 and make sure in your tsconfig.json you have I'll try to extract an example without react. Meanwhile, if you do manage to replicate this, please comment here so I don't waste my time :-) I want to move on to the other problem. |
Question in THIS CODE:
which is calling this:
That's assuming that the error is some type that has ServerTime and Code fields. Is there a type associated with whatever that is? Does one need to be created? |
I was hoping to find a solution to this problem that worked with both typescript 4 (current) and typescript 3 (what this library was built using). I am quickly coming to the conclusion that isn't possible for a few reasons:
I think the solution to this problem is to upgrade the whole library to Typescript 4, but chances are excellent that will break a lot. Some of what it will break is IMO already broken (see #10828) at least in terms of typing (it might actually work because the types overlap enough, so if you don't have strict type checking you get away with it). The only other way I can think of fixing this would be a type guard before callling isTimeSkewedError() but the problem is the error doesn't seem to have a type. I don't feel like upgrading the entire library is something I should undertake. I am going to stop working on this just until contributors who are closer to the project give me some guidance and discussion. |
Hello @wz2b . Thank you for taking the time on investigating about this issue. Checking internally, we need to update the |
That sounds good, assuming the compiler is smart enough to know that yes, it is type guarded, just further down the call stack. I will keep my eyes open and when you push a commit for this I'll help test with 4.9.4 and my tsconfig.json (meaning leave strict and alwaysStrict on and don't bypass catch typing rules) |
Hi @wz2b. I failed trying reproducing this issue with a react app using the same dependencies and However updating this |
Hello @wz2b . I'm trying to reproduce this issue to understand how it would affect other customers. Can you elaborate a little bit more on how you were able to get that error ? |
I don't have any more information but you seemed to understand the problem in a previous comment. The summary is this: in Typescript 4, the argument to In your case, what happens is that you send the error type (any or unknown) on to isTimeSkewedError() without any type guarding. https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#use-unknown-catch-variables describes the problem very well, I'm not sure I have anything to add to it, and I'm not sure why you can't reproduce it. |
Yes, we understand the issue is caused by typescript not being upgraded to a grater version and not having the right type guard. However using the same |
We have published an RFC on our plan for improving TypeScript support in Amplify JS & would love to get your feedback & suggestions! |
The developer preview for v6 of Amplify has officially been released with improvements to TypeScript support and much more! Please check out our announcement and updated documentation to see what has changed. This issue should be resolved within the dev preview and upcoming General Availability for Amplify v6, but let us know with a comment if there are further issues. |
With the release of the latest major version of Amplify (aws-amplify@>6), this issue should now be resolved! Please refer to our release announcement, migration guide, and documentation for more information. |
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
Authentication, Storage
Amplify Categories
auth, storage
Environment information
The npx envinfo command failed but the project configuration is important:
Describe the bug
When trying to build using Typescript 4.9.4, importing the @aws-amplify/storage module, I get this:
Doing some research, this came in with Typescript 4.0 and is described HERE
the apparent mitigation is to change it to this:
Expected behavior
Expected it to compile without warnings
Reproduction steps
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: