Skip to content

@serenity-is/corelib / cast

Function: cast()

cast(instance, type): any

Defined in: src/compat/system-compat.ts:231

Casts instance to type, throwing if the instance is not assignable to the target type.

Parameters

instance

any

The value to cast; null/undefined is returned as-is.

type

Type

The target Type to assert.

Returns

any

instance typed as the target, if the runtime check passes.

Throws

Error string when instance is not an instance of type.