feat(option): better return type for Option constructors#1834
feat(option): better return type for Option constructors#1834JalilArfaoui wants to merge 1 commit into
Conversation
|
Returning specific sum members is a code smell IMO. |
|
Why is that @samhh ? I was under the idea that we want the most precise types we can have, don’t we ? |
|
I've yet to come across a scenario with sum types where it's not a code smell because of an issue with code structure somewhere else. Just because we can do something doesn't mean we should. Less esoterically this might present an issue in some spots where currently widening isn't necessary. I know this was a consideration when designing sum-types though I don't have a specific example to hand. |
|
I'm afraid this might break with typescript 5.5 Note: |
This makes
some()constructor return aSome<A>andnonereturn aNone, more specific than actualOption<A>.This enables this kind of code to work :
without adding à
as option.Some<Session>