forked from vultix/ts-results
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop reusing the val property in both Ok and Err
This is a very backwards incompatible change. Basically the problem is when we had Result<T, E> and T was actually the same as E (or compatible enough) the following mixup was possible where the TS compiler wouldn't say anything[1]: const userIdOkTest: Result<string, string> = Ok("00287b3a-12fb-455c-b3d9-e662153c91b6"); const userIdErrTest: Result<string, string> = Err("User not found"); await doSomethingWithUser(userIdErrTest.val); // runtime error because the compiler didn't complain. // More examples that are not checked for ok or err if (userIdOkTest.val === "test") { console.log("ok or err not checked but it compiles.") } else if (userIdErrTest.val === "test") { console.log("ok or err not checked but it compiles.") } Eliminating the overlap between Ok and Err and providing separate properties for each resolves the issue. [1] vultix#69
- Loading branch information
Showing
7 changed files
with
71 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.