{"record":{"id":"39f0d7a2e4476fd0","repo":"zloirock/core-js","slug":"cannot-convert-a-symbol-value-to-a-string","errorCode":null,"errorMessage":"Cannot convert a Symbol value to a string","messagePattern":"Cannot convert a Symbol value to a string","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core-js/internals/to-string.js","lineNumber":7,"sourceCode":"'use strict';\nvar classof = require('../internals/classof');\n\nvar $String = String;\n\nmodule.exports = function (argument) {\n  if (classof(argument) === 'Symbol') throw new TypeError('Cannot convert a Symbol value to a string');\n  return $String(argument);\n};\n","sourceCodeStart":1,"sourceCodeEnd":10,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/internals/to-string.js#L1-L10","documentation":"core-js's to-string helper (used by String.prototype polyfills, template handling, etc.) deliberately rejects Symbol arguments instead of implicitly converting them. Per spec, operations like `String(sym)` are allowed but many abstract ToString operations must throw when given a Symbol; this helper enforces that. It exists so polyfilled string coercions match the spec and fail loudly rather than producing '[object Symbol]'.","triggerScenarios":"Calling any core-js-polyfilled string-based API with a Symbol argument, e.g. `sym.trim()`, `sym.padStart(5)`, `sym.split('')`, or polyfilled `parseInt(sym)`, `alert(sym)` — anything that routes through to-string.js.","commonSituations":"Using a Symbol as an object property in string interpolation contexts, passing a well-known Symbol (like Symbol.iterator) where a string was expected, accidental argument-order mistakes, or template building that concatenates symbols.","solutions":["Use `String(sym)` or `sym.description` when you explicitly want the symbol's text.","Check the argument being passed is actually a string, not a Symbol.","If you want spec-compliant implicit conversion, use template literals `${sym}` only when the operation allows it (template literals throw too — prefer sym.description)."],"exampleFix":"// before\nconst key = Symbol('id');\nconsole.log(key.padStart(10)); // TypeError\n// after\nconsole.log(String(key.description).padStart(10));","handlingStrategy":"type-guard","validationCode":"if (typeof value === 'symbol') throw new TypeError('Expected a string, got a Symbol');","typeGuard":"function isStringable(v) { return typeof v !== 'symbol'; }","tryCatchPattern":"try {\n  doStringOp(value);\n} catch (e) {\n  if (e instanceof TypeError && /Symbol/.test(e.message)) {\n    doStringOp(String(value.description ?? ''));\n  } else throw e;\n}","preventionTips":["Use sym.description when you want a Symbol's text.","Type-check arguments at API boundaries for typeof 'string'.","Never implicitly concatenate Symbols into strings."],"tags":["core-js","symbol","type-coercion","typeerror"],"backgroundTag":"symbol-to-string-conversion","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}