{"id":11942,"library":"reserved-identifiers","title":"JavaScript Reserved Identifiers","description":"`reserved-identifiers` is a JavaScript library that provides a comprehensive `Set` of reserved identifiers according to the latest ECMAScript specification (currently ES2023) and module context. It offers a straightforward API to retrieve these identifiers, making it easy to check if a given string is reserved in modern JavaScript environments. The library also includes a dedicated export for TypeScript's built-in reserved types, useful for tooling that needs to validate type names. Maintained by Sindresorhus, the package typically sees stable, infrequent releases focused on incorporating new ECMAScript specifications or minor feature enhancements like the recent addition of TypeScript reserved types in v1.1.0 and strict mode identifiers in v1.2.0. Its primary differentiator is its strict adherence to modern JavaScript standards, intentionally omitting support for older JS versions. This focus ensures accuracy for current development practices, distinguishing it from libraries that might cater to a wider range of historical JS versions. The current stable version is 1.2.0.","status":"active","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/sindresorhus/reserved-identifiers","tags":["javascript","reserved","identifiers","keywords","words","restricted","ecmascript","identifier","typescript"],"install":[{"cmd":"npm install reserved-identifiers","lang":"bash","label":"npm"},{"cmd":"yarn add reserved-identifiers","lang":"bash","label":"yarn"},{"cmd":"pnpm add reserved-identifiers","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is the default export. The package is ESM-only and requires import syntax.","wrong":"const reservedIdentifiers = require('reserved-identifiers');","symbol":"reservedIdentifiers","correct":"import reservedIdentifiers from 'reserved-identifiers';"},{"note":"This is a named export. Available since v1.1.0.","wrong":"import typeScriptReservedTypes from 'reserved-identifiers';","symbol":"typeScriptReservedTypes","correct":"import { typeScriptReservedTypes } from 'reserved-identifiers';"}],"quickstart":{"code":"import reservedIdentifiers from 'reserved-identifiers';\nimport { typeScriptReservedTypes } from 'reserved-identifiers';\n\n// Get the default set of reserved identifiers (ES2023 module context)\nconst jsReserved = reservedIdentifiers();\nconst isJsReserved = (identifier) => jsReserved.has(identifier);\n\nconsole.log('Is \"await\" reserved?', isJsReserved('await'));\n//=> true\nconsole.log('Is \"enum\" reserved?', isJsReserved('enum'));\n//=> true\nconsole.log('Is \"myVar\" reserved?', isJsReserved('myVar'));\n//=> false\n\n// Get the set including common global properties\nconst jsReservedWithGlobals = reservedIdentifiers({ includeGlobalProperties: true });\nconst isJsReservedWithGlobals = (identifier) => jsReservedWithGlobals.has(identifier);\n\nconsole.log('Is \"undefined\" reserved (default)?', isJsReserved('undefined'));\n//=> false\nconsole.log('Is \"undefined\" reserved (with globals)?', isJsReservedWithGlobals('undefined'));\n//=> true\n\n// Get TypeScript-specific reserved types\nconst tsReservedTypes = typeScriptReservedTypes();\nconst isTsReservedType = (typeName) => tsReservedTypes.has(typeName);\n\nconsole.log('Is \"any\" a reserved TypeScript type?', isTsReservedType('any'));\n//=> true\nconsole.log('Is \"string\" a reserved TypeScript type?', isTsReservedType('string'));\n//=> true","lang":"javascript","description":"Demonstrates importing both default and named exports, checking JavaScript reserved identifiers (with and without global properties), and checking TypeScript reserved types."},"warnings":[{"fix":"Ensure your target environment supports ES2023 and ESM, or use a different library if older JavaScript compatibility is required.","message":"The library explicitly assumes the latest JavaScript version (ES2023) and a module context. It does not support older JavaScript environments, which means certain identifiers might be considered reserved by this library but not by an older runtime, or vice-versa.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"To include these in the returned set, initialize the set with `reservedIdentifiers({ includeGlobalProperties: true })`.","message":"By default, the `reservedIdentifiers()` set does not include global properties like `globalThis`, `Infinity`, `NaN`, or `undefined`. These are commonly avoided as identifiers but are not strictly 'reserved' by the ECMAScript spec.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to `reserved-identifiers@^1.1.0` or higher to utilize the `typeScriptReservedTypes` export.","message":"The `typeScriptReservedTypes` named export was introduced in version 1.1.0. Attempting to use this export in versions prior to 1.1.0 will result in a `TypeError` or `undefined`.","severity":"breaking","affected_versions":"<1.1.0"},{"fix":"Review code that relies on `isReserved` checks for compatibility, as more identifiers might now be flagged as reserved in applications upgrading from older versions.","message":"In version 1.2.0, 'missing strict mode reserved identifiers' were added to the default set. This means the `Set` returned by `reservedIdentifiers()` may now contain more entries than in previous versions, potentially causing identifiers that were previously deemed non-reserved to now be considered reserved.","severity":"breaking","affected_versions":"<1.2.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use ESM `import` syntax: `import reservedIdentifiers from 'reserved-identifiers';`","cause":"Attempting to import the package using CommonJS `require()` syntax in an ESM-only context (e.g., a modern Node.js project with `type: \"module\"` or browser modules).","error":"ReferenceError: require is not defined"},{"fix":"Use the correct default import syntax: `import reservedIdentifiers from 'reserved-identifiers';`","cause":"Incorrectly attempting to import the default export `reservedIdentifiers` as a named export, e.g., `import { reservedIdentifiers } from 'reserved-identifiers';`.","error":"TypeError: reservedIdentifiers is not a function"},{"fix":"Upgrade the package to `reserved-identifiers@^1.1.0` or higher using `npm install reserved-identifiers@latest`.","cause":"Attempting to use the `typeScriptReservedTypes` named export in a version of the library prior to v1.1.0, where it was introduced.","error":"TypeError: Cannot read properties of undefined (reading 'typeScriptReservedTypes')"}],"ecosystem":"npm"}