3 ms·
No need to ‘return’ when you throw an error, but your approach is valid IMO: if structure / readability is that important, refactor the switch to it’s own metho
by elyseum 5y ago
No need to ‘return’ when you throw an error, but your approach is valid IMO: if structure / readability is that important, refactor the switch to it’s own method with only if checks in it. Hard to make that simpler and more readable.
- notyourday 5y agoIf you don't have a 'return' there's nothing to say that some time later some junior developer would not modify throw to be something else or forget that throw does not return.
- dfee 5y agoThis will prevent the JR dev from making that mistake: https://eslint.org/docs/rules/no-fallthrough https://eslint.org/docs/rules/no-fallthrough
- BiteCode_dev 5y agoThat's what tests are for.