-
Notifications
You must be signed in to change notification settings - Fork 146
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "neverthrow": patch | ||
| --- | ||
|
|
||
| Made err() infer strings narrowly for easier error tagging. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -338,11 +338,11 @@ type CreateTuple<L, V = string> = | |
| }); | ||
|
|
||
| (function it(_ = 'combines only err results into one') { | ||
| type Expectation = Result<[ never, never ], number | string>; | ||
| type Expectation = Result<[ never, never ], number | 'abc'>; | ||
|
|
||
| const result = Result.combine([ | ||
| err(1), | ||
| err('string'), | ||
| err('abc'), | ||
| ]); | ||
|
|
||
| const assignableToCheck: Expectation = result; | ||
|
|
@@ -928,7 +928,7 @@ type CreateTuple<L, V = string> = | |
| }); | ||
|
|
||
| (function it(_ = 'combines only err results into one') { | ||
| type Expectation = Result<[ never, never ], [number, string]>; | ||
| type Expectation = Result<[ never, never ], [number, 'string']>; | ||
|
|
||
| const result = Result.combineWithAllErrors([ | ||
| err(1), | ||
|
|
@@ -999,6 +999,24 @@ type CreateTuple<L, V = string> = | |
| }); | ||
| }); | ||
| }); | ||
|
|
||
| (function describe(_ = 'err') { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| (function it(_ = 'infers the error type narrowly when it is a string') { | ||
| type Expectation = Result<never, 'error'> | ||
|
|
||
| const result = err('error') | ||
|
|
||
| const assignableToCheck: Expectation = result; | ||
| }); | ||
|
|
||
| (function it(_ = 'infers the error type widely when it is not a string') { | ||
| type Expectation = Result<never, { abc: number }> | ||
|
|
||
| const result = err({ abc: 123 }) | ||
|
|
||
| const assignableToCheck: Expectation = result; | ||
| }); | ||
| }) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @m-shaka mentioned we may want to use |
||
| }); | ||
|
|
||
|
|
||
|
|
||
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.