{"id":13350,"library":"is-what-type","title":"is-what-type: Simple Type Checking","description":"is-what-type is a lightweight and comprehensive JavaScript/TypeScript utility library designed for robust type checking of various values. It offers a single default export, `isWhatType`, which returns a string representation of a value's type, alongside numerous named exports like `isString`, `isNumber`, `isObject`, `isArray`, and `isPromise` for specific boolean checks. Currently at version 1.1.4, this library focuses on providing a wide array of type-checking functions, from primitive types to complex browser and Node.js-specific objects like Blob, File, and Buffer, making it suitable for both front-end and back-end development. Its main differentiator lies in its extensive collection of precise `isX` functions and the flexibility of getting a detailed type string, catering to detailed validation scenarios.","status":"active","version":"1.1.4","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/fengxinming/util","tags":["javascript","util","type","typescript"],"install":[{"cmd":"npm install is-what-type","lang":"bash","label":"npm"},{"cmd":"yarn add is-what-type","lang":"bash","label":"yarn"},{"cmd":"pnpm add is-what-type","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary `isWhatType` function is a default export, returning the type name as a string.","wrong":"import { isWhatType } from 'is-what-type';","symbol":"isWhatType","correct":"import isWhatType from 'is-what-type';"},{"note":"CommonJS `require` for specific named exports works, but ESM named imports are preferred in modern TypeScript/JavaScript projects.","wrong":"const isString = require('is-what-type').isString;","symbol":"isString, isNumber","correct":"import { isString, isNumber } from 'is-what-type';"},{"note":"To import all individual `isX` functions into a namespace object, use `* as`. The default export (`isWhatType`) will not be on this object.","wrong":"import TypeChecks from 'is-what-type';","symbol":"all named exports","correct":"import * as TypeChecks from 'is-what-type';"}],"quickstart":{"code":"import isWhatType, { isString, isNumber, isPlainObject, isArray } from 'is-what-type';\n\nconsole.log(isWhatType('hello')); // 'string'\nconsole.log(isWhatType(123));     // 'number'\nconsole.log(isWhatType({ a: 1 }));  // 'object'\nconsole.log(isWhatType([1, 2, 3])); // 'array'\nconsole.log(isWhatType(null));    // 'null'\nconsole.log(isWhatType(undefined)); // 'undefined'\n\nconst myString = 'TypeScript';\nconst myNumber = 42;\nconst myObject = { key: 'value' };\nconst myArray = [true, false];\n\nif (isString(myString)) {\n  console.log(`${myString} is indeed a string.`);\n}\n\nif (isNumber(myNumber)) {\n  console.log(`${myNumber} is definitely a number.`);\n}\n\nif (isPlainObject(myObject)) {\n  console.log(`The value ${JSON.stringify(myObject)} is a plain object.`);\n}\n\nif (isArray(myArray)) {\n  console.log(`The value ${JSON.stringify(myArray)} is an array.`);\n}\n\n// Example with a complex type not always easy to check\nconst myDate = new Date();\nimport { isDate } from 'is-what-type';\nif (isDate(myDate)) {\n  console.log(`${myDate} is a Date object.`);\n}","lang":"typescript","description":"Demonstrates importing both the default `isWhatType` function and several named `isX` type-checking functions, showing their usage with various data types and conditional checks."},"warnings":[{"fix":"Always use `import` statements for both default and named exports (`import isWhatType from 'is-what-type';` or `import { isString } from 'is-what-type';`) when working in an ESM-compatible environment. If CommonJS is required, ensure your bundler or environment correctly transpiles the imports.","message":"Mixing CommonJS `require` with ESM `import` statements for this library can lead to unexpected import resolution issues or runtime errors, especially in environments that strictly enforce ESM.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use `isWhatType(value) === 'typeString'` for reliable comparisons, or prefer the specific named `isX` functions (e.g., `isString(value)`) for boolean checks which are less prone to string comparison errors.","message":"The default export `isWhatType` returns a string (e.g., 'string', 'number', 'array', 'object', 'null', 'undefined'). It is crucial to use strict equality (`===`) when comparing its output, as loose equality (`==`) can lead to subtle bugs.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Understand the distinction: `isObject` will return true for any object, including class instances, while `isPlainObject` is stricter. Choose the appropriate function based on whether you need to check for any object or only plain JSON-like objects.","message":"While comprehensive, the `isPlainObject` function specifically checks for objects created by `Object` constructor or `Object.create(null)`, excluding instances of custom classes or objects with different prototypes.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change your import statement from `import { isWhatType } from 'is-what-type';` to `import isWhatType from 'is-what-type';`.","cause":"Attempting to use `isWhatType` as a named import when it is a default export in a bundled environment (e.g., Webpack/Rollup).","error":"TypeError: (0 , is_what_type__WEBPACK_IMPORTED_MODULE_0__.isWhatType) is not a function"},{"fix":"Ensure you are using named imports correctly: `import { isString } from 'is-what-type';`. If using CommonJS, it should be `const { isString } = require('is-what-type');`.","cause":"Attempting to access a named export (`isString`) from the default import or a CommonJS `require()` call that resolves to the default export without destructuring.","error":"TypeError: Cannot read properties of undefined (reading 'isString')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null}