{"record":{"id":"6ed12e3ade38b643","repo":"zloirock/core-js","slug":"symbol-is-not-a-symbol-dynamic-trytostring-sym","errorCode":null,"errorMessage":"<symbol> is not a symbol (dynamic: tryToString(sym) + ' is not a symbol')","messagePattern":"<symbol> is not a symbol \\(dynamic: tryToString\\(sym\\) \\+ ' is not a symbol'\\)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core-js/modules/es.symbol.key-for.js","lineNumber":15,"sourceCode":"'use strict';\nvar $ = require('../internals/export');\nvar hasOwn = require('../internals/has-own-property');\nvar isSymbol = require('../internals/is-symbol');\nvar tryToString = require('../internals/try-to-string');\nvar shared = require('../internals/shared');\nvar NATIVE_SYMBOL_REGISTRY = require('../internals/symbol-registry-detection');\n\nvar SymbolToStringRegistry = shared('symbol-to-string-registry');\n\n// `Symbol.keyFor` method\n// https://tc39.es/ecma262/#sec-symbol.keyfor\n$({ target: 'Symbol', stat: true, forced: !NATIVE_SYMBOL_REGISTRY }, {\n  keyFor: function keyFor(sym) {\n    if (!isSymbol(sym)) throw new TypeError(tryToString(sym) + ' is not a symbol');\n    if (hasOwn(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym];\n  }\n});\n","sourceCodeStart":1,"sourceCodeEnd":19,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/modules/es.symbol.key-for.js#L1-L19","documentation":"Symbol.keyFor requires its argument to be an actual symbol registered in the global symbol registry. core-js validates with isSymbol and throws a TypeError prefixed with a tryToString of the argument (e.g. \"42 is not a symbol\"). With NATIVE_SYMBOL_REGISTRY native engines throw the equivalent 'x is not a symbol' TypeError; the polyfill version makes the offending value visible in the message.","triggerScenarios":"Symbol.keyFor(42), Symbol.keyFor('foo'), Symbol.keyFor(Symbol('x')) — keyFor does NOT look up unregistered symbols created by Symbol(), only registry symbols from Symbol.for; passing a string that came from a deserialized key back to keyFor without converting via Symbol.for first.","commonSituations":"Round-tripping symbol keys through JSON/localStorage (Symbols stringify to 'Symbol(id)' strings) then calling keyFor on the string; caching layer storing registry keys as strings; code confusion between Symbol.for (register + keyFor lookup) and Symbol (unregistered); TypeScript types widening the parameter to any after an untyped API boundary.","solutions":["Ensure the argument is a real symbol: convert string keys with Symbol.for(key) before calling keyFor.","Check typeof v === 'symbol' before calling Symbol.keyFor.","Remember keyFor returns undefined for Symbol()-created (unregistered) symbols — use Symbol.for if you need registry lookup.","Fix the data source so symbols are not serialized to strings; store the registry key string separately instead."],"exampleFix":"// before\nconst key = cache.get('myKey'); // stored as string\nSymbol.keyFor(key); // TypeError: myKey is not a symbol\n// after\nconst key = cache.get('myKey');\nSymbol.keyFor(typeof key === 'string' ? Symbol.for(key) : key);","handlingStrategy":"type-guard","validationCode":"function keyForSafe(v) {\n  if (typeof v !== 'symbol') return undefined;\n  return Symbol.keyFor(v);\n}","typeGuard":"function isRegisteredSymbol(v) {\n  return typeof v === 'symbol' && Symbol.keyFor(v) !== undefined;\n}\n// usage: if (isRegisteredSymbol(sym)) const key = Symbol.keyFor(sym);","tryCatchPattern":"try {\n  const key = Symbol.keyFor(sym);\n} catch (e) {\n  if (e instanceof TypeError && /is not a symbol/.test(e.message)) {\n    // convert or reject: const key = Symbol.for(String(sym));\n  } else throw e;\n}","preventionTips":["Always typeof-check for 'symbol' before Symbol.keyFor.","Distinguish Symbol() (unregistered) from Symbol.for() (registered) in your code.","Do not serialize Symbols through JSON/storage; persist the registry key string instead.","Type API parameters as symbol, not any, to catch misuse at compile time."],"tags":["javascript","polyfill","symbol","typeerror"],"backgroundTag":"symbol-keyfor-not-a-symbol","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}