@geronimus/type-err

0.1.2 • Public • Published

TypeErr( refName, expectedTypeName, foundInstance )

Returns a new instance of a TypeError with the error message:

Reference name: refName
  Expected: expectedTypeName
  Actual: either typeof foundInstance or, if foundInstance is of type object, then foundInstance.constructor.name.

Examples

const TypeErr = require( "@geronimus/type-err" );

function hello( who ) {

  if ( typeof who !== "string" )
    throw TypeErr( "who", "string", who );
  else
    console.log( `Hello, ${ who }!` );
}

Parameters

param string

The parameter, variable, or reference name where the invalid type was found.

expectedTypeName string

The type that is expected or allowed.

foundInstance any

The reference that you found to be of the wrong type.

The function will resolve its name for display in the error message. If the instance is a primitive value, then its typeof name will be displayed. If it is an object, then the message will display the name of its constructor.

Notes

If you do not provide meaningful arguments, the generated message will be meaningless.

Readme

Keywords

none

Package Sidebar

Install

npm i @geronimus/type-err

Weekly Downloads

1

Version

0.1.2

License

BSD-2-Clause

Unpacked Size

3.98 kB

Total Files

4

Last publish

Collaborators

  • geronimus