type_assert

Raises a type_err() if the specified expression evaluates to false.

This function does not generate a change.

Function

assert(expression, type(s) [, error_msg])

Arguments

Argument Type Description
expression any (required) The result of this expression will be type tested.
type(s) str/list (required) Type name or list with type names to check.
error_msg str (optional) Custom error message.

Return value

Returns nil if the type of the expression evaluates to true. Otherwise an type_err() is raised.

Example

This code shows how assert can be used:

type_assert("one", "int");

Raises a type_err() exception

{
    "error_msg": "invalid type `str`",
    "error_code": -61
}

Or, use a list of type names to check

type_assert(3.14, ["int", "float"]);

Return value in JSON format

null