Make switches exhaustive with never
A default branch that assigns the value to never fails to compile the moment someone adds a case you did not handle.
switch (result.kind) {
case "text": return renderText(result);
case "table": return renderTable(result);
default: {
const _exhaustive: never = result;
return _exhaustive;
}
}The terminal on this site has a dozen result kinds and this line has caught every one I forgot.
typescript