{"id":11159,"library":"js-types","title":"JavaScript Built-in Types List","description":"The `js-types` package provides a comprehensive, programmatically accessible list of built-in JavaScript data types, primarily sourced from MDN Web Docs. It is currently at stable version 4.0.0, which requires Node.js 18.20 and is a pure ESM package. The package maintains a moderate release cadence, with major versions often coinciding with significant Node.js LTS updates and new ECMAScript feature adoptions. Its key differentiator lies in its straightforward design: the core data is simply a `js-types.json` file that can be directly imported, making it highly portable and easy to integrate across various JavaScript environments—from Node.js backend services to browser-side applications—without introducing complex dependencies. This makes it an ideal utility for tasks like runtime type checking, generating documentation, or any scenario requiring a definitive, up-to-date enumeration of JavaScript's fundamental types.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/sindresorhus/js-types","tags":["javascript","js","ecmascript","builtin","types","type","data","list","typescript"],"install":[{"cmd":"npm install js-types","lang":"bash","label":"npm"},{"cmd":"yarn add js-types","lang":"bash","label":"yarn"},{"cmd":"pnpm add js-types","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Since v4.0.0, this package is pure ESM and must be imported using ES modules syntax. CommonJS `require()` is not supported.","wrong":"const jsTypes = require('js-types');","symbol":"jsTypes","correct":"import jsTypes from 'js-types';"},{"note":"The raw JSON file can be imported directly for scenarios where the array of strings is sufficient. This is also ESM-only since v4.0.0.","wrong":"const typesJson = require('js-types/js-types.json');","symbol":"typesJson","correct":"import typesJson from 'js-types/js-types.json';"},{"note":"While `js-types` ships with TypeScript definitions, the default export is an array of strings. This example shows how to derive a union type of all possible JavaScript type names.","symbol":"Type (TypeScript)","correct":"type JSTypeName = typeof import('js-types')[number];"}],"quickstart":{"code":"import jsTypes from 'js-types';\n\nconsole.log('--- All JavaScript Built-in Types ---');\nconsole.log(`Total types found: ${jsTypes.length}`);\nconsole.log(jsTypes.join(', '));\n\n// Example: Check if a specific type is in the list\nconst typeToCheck = 'Map';\nif (jsTypes.includes(typeToCheck)) {\n  console.log(`\\n'${typeToCheck}' is a recognized JavaScript built-in type.`);\n} else {\n  console.log(`\\n'${typeToCheck}' is NOT in the list of JavaScript built-in types.`);\n}\n","lang":"typescript","description":"Demonstrates how to import the list of JavaScript types and perform basic operations, such as listing all types and checking for the presence of a specific type. This highlights the primary use case of accessing the array of type names."},"warnings":[{"fix":"Migrate your import statements from `const jsTypes = require('js-types');` to `import jsTypes from 'js-types';`. Ensure your project's `package.json` has `\"type\": \"module\"` or uses `.mjs` file extensions for ESM compatibility.","message":"Version 4.0.0 of `js-types` is now a pure ECMAScript Module (ESM) and no longer supports CommonJS `require()`. You must update your project to use `import` statements.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Upgrade your Node.js environment to version 18.20 or later. Use `nvm` or your preferred Node.js version manager to switch versions.","message":"Version 4.0.0 explicitly requires Node.js 18.20 or newer. Running on older Node.js versions will result in errors.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Upgrade your Node.js environment to version 18 or later. For v4.0.0, ensure it's at least 18.20.","message":"Version 3.0.0 required Node.js 18 or newer. If you are upgrading from an older version directly to v3.x or v4.x, ensure your Node.js version meets these minimums.","severity":"breaking","affected_versions":">=3.0.0 <4.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Update your import statement from `const jsTypes = require('js-types');` to `import jsTypes from 'js-types';`. Ensure your project configuration supports ES modules (e.g., `\"type\": \"module\"` in `package.json`).","cause":"Attempting to use `require()` to import `js-types` in a CommonJS context when the package is pure ESM.","error":"ERR_REQUIRE_ESM"},{"fix":"Always use the full import path for the default export: `import jsTypes from 'js-types';` or specific files like `import typesJson from 'js-types/js-types.json';`.","cause":"This error can occur if you're trying to import the package using a path like `import 'js-types';` without specifying the default export or if there's a misconfiguration in how your bundler/Node.js resolves ESM.","error":"Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'js-types' is not supported resolving ES modules"},{"fix":"Refactor your code to use ES module equivalents. For `__dirname`, use `import.meta.url` and `path.dirname(fileURLToPath(import.meta.url))`.","cause":"When migrating to pure ESM, CommonJS globals like `__dirname`, `__filename`, and `require` are no longer available in the module scope.","error":"TypeError: __dirname is not defined in ES module scope"}],"ecosystem":"npm"}