You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionassertUnreachable(value: never): never{thrownewError(`Missed a case! ${value}`);}functiondrawShape(shape: Shape,context: CanvasRenderingContext2D){switch(shape.type){case'box':
context.rect(...shape.topLeft, ...shape.size);break;case'circle':
context.arc(...shape.center,shape.radius,0,2*Math.PI);break;default:
assertUnreachable(shape);// ~~~~~// ... type 'Line' is not assignable to parameter of type 'never'.}}
functiongetArea(shape: Shape): number{// ~~~~~~ Function lacks ending return statement and// return type does not include 'undefined'.switch(shape.type){case'box':
const[width,height]=shape.size;returnwidth*height;case'circle':
returnMath.PI*shape.radius**2;}}
functionprocessShape(shape: Shape){switch(shape.type){case'box': break;case'circle': break;default:
constexhaustiveCheck: never=shape;// ~~~~~~~~~~~~~~~ Type 'Line' is not assignable to type 'never'.thrownewError(`Missed a case: ${exhaustiveCheck}`);}}
functionprocessShape(shape: Shape){switch(shape.type){case'box': break;case'circle': break;default:
shapesatisfies never
// ~~~~~~~~~ Type 'Line' does not satisfy the expected type 'never'.thrownewError(`Missed a case: ${shape}`);}}