4 ms·
Better to return a union of custom result types. Save exceptions for when stuff goes really wrong.
by macca321 6y ago
Better to return a union of custom result types. Save exceptions for when stuff goes really wrong.
- emteycz 6y agoIt would be better to improve typing of Promise and try/catch than additional layers, IMHO
- eyelidlessness 6y agoUnfortunately that’s not idiomatic in many common JS/TS scenarios, and requires deep familiarity with the internals of any APIs or third party libraries that throw errors. Optional typed exceptions would be right in line with the TS approach of modeling real world JS usage, but for the syntactical question of exhaustive error handling. (Of course that could be addressed separately or not at all.)