Hacker News new | ask | show | jobs
by macca321 2038 days ago
Better to return a union of custom result types. Save exceptions for when stuff goes really wrong.
2 comments

Unfortunately 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.)
It would be better to improve typing of Promise and try/catch than additional layers, IMHO