-
Notifications
You must be signed in to change notification settings - Fork 114
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
Require a return value for all transformative functions #190
base: develop
Are you sure you want to change the base?
Conversation
…s included with strict
This enforces that calls to map, leftMap, cata, etc. provide a return value where it is expected.
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.
Thanc
ks for contribution!
- We shouldn't enforce TS higher than 3.0.x in
0.9.0
so this PR wil wait till post release - This should also include all
flatMap
s,chain
s,bind
s andcatchMap
s
👍
@@ -31,7 +31,7 @@ | |||
"karma-firefox-launcher": "1.1.0", | |||
"karma-jasmine": "1.1.2", | |||
"karma-mocha-reporter": "2.2.5", | |||
"typescript": "3.0.3", | |||
"typescript": "3.1.3", |
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.
it would be nice to not enforce upgrade to TS higher than 3.0
// uncomment to fail typecheck for non return value | ||
// twelve.map(() => { "no return"; }); | ||
// twelve.leftMap(() => { "no return"; }); | ||
// twelve.cata(() => { "no return" }, () => { "no return"; }); |
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.
cata should allow to return void
Use of I'd just not allow chaining - call to side effects should e the last thing done ;) Optionally we may introduce WDYT @jleider ? |
@jleider - is there a chance you'd continue on this? |
@ulfryk Unfortunately not, we migrated to https://gcanti.github.io/fp-ts/ even though they don't provide a |
This enforces that calls to
map
,leftMap
,cata
, etc. provide a return value where it is expected.One caveat to note is that users will find that side-effectual code will now throw type errors. For example, we use
cata
/fold
fairly extensively in our codebase. Some of the cases we had side-effectual functions that didn't have a return value. These now need to be wrapped inIO
. Additionally, there could be a convenience function that would operate on both left/right, some/none, etc. likecata
but for side-effects similar toforEach
since currently there is no way to chainforEach
andorElseRun
because they both returnvoid
instead ofthis
.Requires TypeScript 2.8+.