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
When looking at functions in typescript. We can see what arguments it takes and their types as well as the type it will return. But what we don't know is if anywhere down the line of this function is if it uses the throw keyword. If it does and we don't know about it then this can very much change the behaviour of our resumed predictable code.
My suggestion is that when looking at the function signature, it indicates in some method where it could throw or not. This flag would bubble up to any function that uses the function that could throw unless wrapped inside a try catch block.
This should also apply to functions like fetch, which doesn't actually have the throw keyword in it, but can still throw.
π Motivating Example
This feature can help developers know and plan where and when to wrap stuff in try catch blocks to catch this undefined behaviour that somewhere further down the code breaks for an unexpected reason. The throw keyword is not a mistake of JavaScript. It is a feature and we should have better features to know when it has been used.
π» Use Cases
What do you want to use this for?
To know if a function may break and stop it from breaking the rest of my code, without adding unnecessary try catch blocks.
What shortcomings exist with current approaches?
We currently have no way to know if a function may throw, with the exception of documentation or looking at source code.
What workarounds are you using in the meantime?
Assuming these are fine until they break with a new unknown error.
The text was updated successfully, but these errors were encountered:
π Search Terms
Throw
Function signature
β Viability Checklist
β Suggestion
When looking at functions in typescript. We can see what arguments it takes and their types as well as the type it will return. But what we don't know is if anywhere down the line of this function is if it uses the
throw
keyword. If it does and we don't know about it then this can very much change the behaviour of our resumed predictable code.My suggestion is that when looking at the function signature, it indicates in some method where it could throw or not. This flag would bubble up to any function that uses the function that could throw unless wrapped inside a try catch block.
This should also apply to functions like
fetch
, which doesn't actually have the throw keyword in it, but can still throw.π Motivating Example
This feature can help developers know and plan where and when to wrap stuff in try catch blocks to catch this undefined behaviour that somewhere further down the code breaks for an unexpected reason. The throw keyword is not a mistake of JavaScript. It is a feature and we should have better features to know when it has been used.
π» Use Cases
To know if a function may break and stop it from breaking the rest of my code, without adding unnecessary try catch blocks.
We currently have no way to know if a function may throw, with the exception of documentation or looking at source code.
Assuming these are fine until they break with a new unknown error.
The text was updated successfully, but these errors were encountered: