Function: isType()
ts
function isType(type, value): boolean;Checks if a value's type matches the specified type string. 检查值的类型是否与指定的类型字符串匹配。
Parameters
| Parameter | Type | Description |
|---|---|---|
type | string | The type string to check against / 要检查的类型字符串 |
value | unknown | The value to check the type of / 要检查类型的值 |
Returns
boolean
True if the value's type matches the specified type string / 如果值的类型匹配指定的类型字符串则返回true
Example
typescript
isType('String', 'hello') // => true
isType('Number', 42) // => true
isType('Array', [1, 2, 3]) // => true
isType('Object', {}) // => true
isType('RegExp', /test/) // => true
isType('Date', new Date()) // => true
isType('Function', () => {}) // => true
isType('Array', {}) // => false
isType('String', 123) // => falseSince
1.0.0