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
Pass typing-helpers to safeTry's body #500
base: master
Are you sure you want to change the base?
Pass typing-helpers to safeTry's body #500
Conversation
The example you have given does pass type checks for me. Maybe it depends on the version of TypeScript that's being used? EDIT: I just checked, all of the examples given do pass type checks: https://www.typescriptlang.org/play?ts=5.2.2#code/JYWwDg9gTgLgBAbzhA1gGjgUylDBnAQwDNMAVKATzgF84ioIQ4ByAO0wDdsYALBgd2YBuAFAjCJchQA8SGBTCYAXHABERCBFU0MAV1YpWEfqwB8ACiL6AxjGARWAKjjmAlIhFwvcKJhi6oVmQUczkFZTUNLRpXEWpY8WIySml9Q2NWDDDFFXVNbWoLK1ZbeycXdwRPbwB6GrhSHmA8OAADbChWuGa4fh4CeB7MAA9IWEwAEzgAIyp2Llg+Y2qvX39ArBxQuHkcyPyYuISJZJk0oxMsnfDcqIKimzsHZzcPbzgKYEwAGwnnDvM+gmmCIwHYE1cADoQAQwABRLavAC8phcVXe712ETyWhWMShJwAqqx+FBYW48WsAkFUOZVHhGH4mqwAOaqWLxERAA |
Thank you for taking your time to try reproducing it. I'm not sure I understand what happens here because I'm not used to using playground with imports, but it seems not working in those cases because it seems this also passes the check. (I say 'seems' because I could not find any compilation outputs, and the only clue I had was that no red underlines showed up there.) However, I also confirmed that my examples do pass with the version of Typescript of this repository by adding them in I'll fix examples and documents in this PR. Thank you. |
Co-authored-by: Johannes Loher <johannes.loher@fg4f.de>
@ghost91- |
Edit: The descriptions for
ok
anderr
in this comment is wrong. Please see the following comments.With
safeTry
, sometimes we need to specify type parameters to pass type-checks.For example, the following will not pass type-checks because the body's return type (
T
) is inferred to be{ type: string }
A naive solution is to specify the body's type parameters like
but this requires many keystrokes and obviously cumbersome.
With this PR, properly typed helpers will be passed to the body so that we will not be required to specify type parameters.
For example,
The helpers are
ok
,err
anderror
. Please see the comments on the code.This is not a breaking change.