isTypeError

Test if a value is a TypeError object.

Usage

var isTypeError = require( '@stdlib/assert/is-type-error' );

isTypeError( value )

Tests if a value is a TypeError object.

var bool = isTypeError( new TypeError( 'beep' ) );
// returns true

Notes

  • This function should not be considered robust. While the function should always return true if provided a TypeError (or a descendant) object, false positives may occur due to the fact that the TypeError constructor inherits from Error and has no internal class of its own. Hence, TypeError impersonation is possible.

Examples

var isTypeError = require( '@stdlib/assert/is-type-error' );

var bool = isTypeError( new TypeError( 'type error' ) );
// returns true

bool = isTypeError( new Error( 'error' ) );
// returns false

bool = isTypeError( new EvalError( 'eval error' ) );
// returns false

bool = isTypeError( new ReferenceError( 'reference error' ) );
// returns false

bool = isTypeError( new SyntaxError( 'syntax error' ) );
// returns false

bool = isTypeError( new RangeError( 'range error' ) );
// returns false

bool = isTypeError( new URIError( 'URI error' ) );
// returns false

bool = isTypeError( {} );
// returns false

bool = isTypeError( null );
// returns false