{"id":12265,"library":"typpy","title":"Typpy: Enhanced Type Checking","description":"Typpy is a lightweight JavaScript utility that provides a more robust and accurate approach to determining variable types compared to the native `typeof` operator. It addresses common ambiguities of `typeof`, such as `null` evaluating to \"object\" and distinguishing between different object types like arrays and plain objects. The library allows for type comparison against both string representations (e.g., \"array\") and constructor functions (e.g., `Array`). Currently at version 2.4.0, its release cadence is moderate, primarily consisting of minor updates for documentation, sponsor links, and small bug fixes like handling null/undefined constructors. It differentiates itself by offering a consolidated API for precise type checks, simplifying conditional logic and reducing potential type-related bugs in applications.","status":"active","version":"2.4.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/IonicaBizau/typpy","tags":["javascript","typeof","typpy"],"install":[{"cmd":"npm install typpy","lang":"bash","label":"npm"},{"cmd":"yarn add typpy","lang":"bash","label":"yarn"},{"cmd":"pnpm add typpy","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For ESM, use default import. The package's primary export is a callable function that also carries `is` and `get` methods as properties. CommonJS `require` is still widely used in older Node.js projects, but `import` is preferred for modern JavaScript.","wrong":"const Typpy = require('typpy');","symbol":"Typpy","correct":"import Typpy from 'typpy';"},{"note":"The `is` method is a property of the default `Typpy` export, not a standalone named export. It's accessed directly via the imported `Typpy` object/function.","wrong":"import { is } from 'typpy';","symbol":"Typpy.is","correct":"import Typpy from 'typpy'; Typpy.is(value, type);"},{"note":"Similar to `Typpy.is`, the `get` method is a property of the default `Typpy` export, not a named export. Access it via `Typpy.get` after importing the default.","wrong":"import { get } from 'typpy';","symbol":"Typpy.get","correct":"import Typpy from 'typpy'; Typpy.get(value);"}],"quickstart":{"code":"import Typpy from 'typpy';\n\nconsole.log(Typpy(0));\n// => \"number\"\n\nconsole.log(Typpy('', String));\n// => true\n\nconsole.log(Typpy.is(null, 'null'));\n// => true\n\nconsole.log(Typpy.get([]));\n// => Array\n\nconsole.log(Typpy({}, true));\n// => false\n\nconsole.log(Typpy({}, Object));\n// => true\n\nconsole.log(Typpy.get({}));\n// => Object\n\nconsole.log(Typpy.get(42, true));\n// => \"number\"","lang":"javascript","description":"This example demonstrates how to use the main `Typpy` function to get a type string or compare against a target, and how to use the `Typpy.is` and `Typpy.get` helper methods for specific type checks."},"warnings":[{"fix":"Use `import Typpy from 'typpy';` and then `Typpy.is(...)` or `Typpy.get(...)` for ESM. For CommonJS, `const Typpy = require('typpy');` remains valid.","message":"The documentation primarily showcases CommonJS `require` syntax. While modern Node.js and bundlers support `import Typpy from 'typpy';` for ESM, direct named exports like `import { is } from 'typpy';` are not provided. Always import the default `Typpy` object and access `is` and `get` as properties.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"When using `Typpy(input, target)`, check for a boolean result. When using `Typpy(input)` to get the type, expect a string. If consistent boolean results are desired, prefer `Typpy.is(input, target)`.","message":"Typpy's primary function `Typpy(input, target)` returns a boolean if `target` is provided, but a string if `target` is omitted. Ensure you handle both return types correctly in your logic.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Leverage `Typpy`'s accurate `null` checking. If you specifically need the native `typeof` behavior, use the built-in operator directly. For consistent and precise type checking across all primitive and object types, stick with `Typpy`.","message":"Unlike the native `typeof` operator which returns 'object' for `null`, `Typpy.is(null, 'null')` correctly evaluates to `true`. Be aware of this difference when migrating code or expecting native `typeof` behavior.","severity":"gotcha","affected_versions":">=2.4.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 to `import Typpy from 'typpy';` and then call `Typpy.is(value, type);`.","cause":"Attempting to import `is` as a named export (`import { is } from 'typpy';`) instead of accessing it as a property of the default export.","error":"TypeError: Typpy.is is not a function"},{"fix":"Update your import statement to use ESM syntax: `import Typpy from 'typpy';`.","cause":"Using `const Typpy = require('typpy');` in an environment configured for ECMAScript Modules (ESM) without a CommonJS shim.","error":"ReferenceError: require is not defined"},{"fix":"First, ensure the package is installed: `npm install typpy`. Then, verify the import statement `import Typpy from 'typpy';` (for ESM) or `const Typpy = require('typpy');` (for CommonJS) is correct and at the top of your file.","cause":"The Typpy package was not correctly installed or imported. This could be due to a typo in the import path or a missing `npm install typpy` step.","error":"Typpy is not defined"}],"ecosystem":"npm"}