Skip to content

castError

Functions

castError()

castError(value, options): Error

转换值为 Error

Parameters

ParameterTypeDescription
valueany检测值
optionsObject配置项
options.cause?any错误原因,若未设置默认在 valueError 类型时存储其自身值

Returns

Error

Example

ts
castError(1)
// => Error { name: 'error', message: '1', cause: 1 }

castError(new Error('This is error'))
// => Error { name: 'error', message: 'This is error' }