3 ms·
I'm surprised the list doesn't mention untyped-exception and how to deal with the inability to figure out the type from the catch block. Untyped exception in T
by valand 6y ago
I'm surprised the list doesn't mention untyped-exception and how to deal with the inability to figure out the type from the catch block.
Untyped exception in TypeScript is one of the most vulnerable point of static type escapes. Unlike any, which is explicit, exception caught in catch block is implicit.
Personally I prefer to wrap catches into a specific type/symbol `UnknownError { data: unknown }`, and discriminated union to indicate success/failure on return. fp-ts (https://github.com/gcanti/fp-ts https://github.com/gcanti/fp-ts) is my go-to library for this