3 ms·
Similar reason why you can’t have exception types in TypeScript. The underlying runtime and language doesn’t allow it to work.
by msoad 3y ago
Similar reason why you can’t have exception types in TypeScript. The underlying runtime and language doesn’t allow it to work.
- msoad 3y agoHere is more explaining of what I mean. Coming from other languages you might think TypeScript can add a `throws` type annotation so caller can expect the type of error in the `catch` block. Something like this: function parse(input: string): string, throws SyntaxError {} However in JavaScript we can not guarantee that when calling `parse` the only error you might get is the error that this function throws. So there is no point in adding type annotation