TypeError 类


表示提供的参数不是允许的类型。 例如,将函数传给期望字符串为 TypeError 的参数。

require('node:url').parse(() => { });
// 抛出 TypeError,因为它期望字符串。

Node.js 将立即生成并抛出 TypeError 实例作为参数验证的一种形式。

Indicates that a provided argument is not an allowable type. For example, passing a function to a parameter which expects a string would be a TypeError.

require('node:url').parse(() => { });
// Throws TypeError, since it expected a string.

Node.js will generate and throw TypeError instances immediately as a form of argument validation.