Typescript: Catch error types
result.body = error.message compile error, because the type of the object ’error’ is unknown result.body = (error as AWSError).message force casting hides the error, but gives no guarantee that message actually exists! there is no guarantee that error is of type AWSError and actually has that field! And non of the ‘as’ casting remains at runtime So it will just act like message = ‘undefined’ if it is not there...