-
Notifications
You must be signed in to change notification settings - Fork 141
Made err() infer strings narrowly for easier error tagging #563
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
Made err() infer strings narrowly for easier error tagging #563
Conversation
🦋 Changeset detectedLatest commit: eadf50c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| export const ok = <T, E = never>(value: T): Ok<T, E> => new Ok(value) | ||
|
|
||
| export const err = <T = never, E = unknown>(err: E): Err<T, E> => new Err(err) | ||
| export function err<T = never, E extends string = string>(err: E): Err<T, E> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do this with an overloaded type if you'd prefer, but figured this was the easiest way to make this change.
| }); | ||
| }); | ||
|
|
||
| (function describe(_ = 'err') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't sure where this test should go, so made its own block.
|
|
||
| const assignableToCheck: Expectation = result; | ||
| }); | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note - prettier can't run on this file because it's an outdated version and there's an 'import type'.
When I did try to run prettier on it, a LOT of changes were made, probably to do with the semicolons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m-shaka mentioned we may want to use biome instead of prettier, but perhaps if we just update prettier this issue goes away?
|
Thanks for the contribution @mattpocock :) |
|
Just found this in the blame while working on #584. Nice work @mattpocock. It might be useful for |
I would like
errto infer strings more narrowly. This would make it easier to create unions out of possible string errors.This would infer as
Ok<number> | Err<'Too low'> | Err<'Too high'>.Let me know if this is desirable.