3 ms·
What I really want JS/TS is one of my favorite features about Swift: Throwing functions in Swift don't throw traditional exceptions (please someone up the stac
by nielsbot 2y ago
What I really want JS/TS is one of my favorite features about Swift:
Throwing functions in Swift don't throw traditional exceptions (please someone up the stack catch this). Throwing an error in Swift actually returns an Error to the calling function instead of that function's normal result type. Swift also enforces that when you call code that might "throw" (return an error instead of a result) you either handle the error or "rethrow" it.
In TS I use this pattern:
`type ErrorThrowingFunction = <T,>() => T|Error`
But it's not nearly as nice to use in TS since it's not a language feature.
- satvikpendem 2y agoThat's basically Rust's `?` operator, along with its upcoming Try trait