4 ms·
It makes the errors that a function can fail with part of that function's type.
by riwsky 2y ago
It makes the errors that a function can fail with part of that function's type.
- galaxyLogic 2y agoI see, I think. I sometimes write JavaScript functions which instead of throwing an error return an error-instance. If the caller knows what kind of result may be returned it can check if it is "instanceof Error" or of some subclass of Error and handle it somehow. (Sum-)Types would of course be helpful in making it clear that the function can sometimes return an instance of some specific Error-subclasses of course. Now I assume I could do something like that in plain TypeScript also, return error-instances of different error-subclasses and declare them to be possible return-types, and then handle them in the caller or its callers somehow. Anybody getting the error-result could not pass it or return it to anybody else whose type does not expect an error-instance. Is there something even better with EffectsTS?