"use strict";classMouthSizeArgumentCountErrorextendsError{constructor(message:string){super(message);this.name="MouthSizeArgumentCountError";}}classMouthSizeTypeErrorextendsError{constructor(message:string){super(message);this.name="MouthSizeArgumentCountError";}}typeMouthSize="small"|"wide";functionmouthSize(animal:string):MouthSize{if(arguments.length!==1){thrownewMouthSizeArgumentCountError("Expected exactly one argument");}if(typeofanimal!=="string"){thrownewMouthSizeTypeError("Expect argument to be a string");}if(animal.trim().toLowerCase()==="alligator"){return"small";}return"wide";}console.log(mouthSize("alligator"));// "small"console.log(mouthSize("aLlIgAtOr"));// "small"console.log(mouthSize("fox"));// "wide"try{// @ts-ignoremouthSize();// @ts-ignoremouthSize("fox","alligator");}catch(error){if(errorinstanceofMouthSizeArgumentCountError){console.log("argument count error");}}try{// @ts-ignoremouthSize(123);}catch(error){if(errorinstanceofMouthSizeTypeError){console.log("argument type error");}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
TypeScript