You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check the sample code. It represents some fetch-request (0) and transformation of its results (1). For some reasons (inattention) I return error in Promise.catch (3).
What do I expect?
I expect that error (4.0) type (and then data (4.1) type) will be of type "unknown" and IDE will underline spreading data at transformation (1), typechecks will fail, etc --> I will notice the error --> I will prevent the error in runtime.
What do I get?
Error (4.0) type (and then data (4.1) type) are "any" and IDE didn't underline the error, typechecks didn't fail, etc --> I didn't notice the error --> I got TypeError in runtime, cos the error value (5) is not iterable.
Of course, I can add type annotation "error: unknown" in catch callback on my own, but I think it should be automatically inferred with flags I mentioned before. Or maybe create a new flag for this case. Or maybe change Promise.catch definition. Or maybe I don't understand something, please explain me!
⚙ Compilation target
esnext
⚙ Library
lib.es5
Missing / Incorrect Definition
Promise.catch
Important:
strict mode is enabled. "useUnknownInCatchVariables" is not disabled.
Description
Check the sample code. It represents some fetch-request (0) and transformation of its results (1). For some reasons (inattention) I return error in Promise.catch (3).
What do I expect?
I expect that error (4.0) type (and then data (4.1) type) will be of type "unknown" and IDE will underline spreading data at transformation (1), typechecks will fail, etc --> I will notice the error --> I will prevent the error in runtime.
What do I get?
Error (4.0) type (and then data (4.1) type) are "any" and IDE didn't underline the error, typechecks didn't fail, etc --> I didn't notice the error --> I got TypeError in runtime, cos the error value (5) is not iterable.
Investigation
In other issue, where author was requesting for generic for rejected promise values, rbuckton agreed that type "any" is the most accurate type for rejected promises values. It was ~2-3 years before type "unknown" was introduced, though 🤔!..
Potential solution
Of course, I can add type annotation
"error: unknown"
in catch callback on my own, but I think it should be automatically inferred with flags I mentioned before. Or maybe create a new flag for this case. Or maybe change Promise.catch definition. Or maybe I don't understand something, please explain me!Sample Code
Documentation Link
No response
The text was updated successfully, but these errors were encountered: