parseSymbol
Parses a value into a symbol. This parser uses the validateSymbol primitive validator to ensure that the input is a symbol primitive. No normalization is performed.
The parser never throws and never mutates input. It returns a structured ParseResult<symbol> describing success or failure.
Signature
function parseSymbol(
value: unknown,
field?: string
): ParseResult<symbol>
Behavior
- Accepted Inputs:
- Symbol primitives (
Symbol('id'),Symbol.iterator) - Rejected Inputs:
- Boxed Symbol objects (
Object(Symbol('x'))). - Numbers, strings, and booleans.
- Objects, arrays, functions.
nullandundefined.- These produce: "Value must be a symbol"
Returns
ok: trueAnd the symbol when parsing succeeds.ok: false, value: nullAnd a list of issues when parsing fails.
Examples
parseSymbol(Symbol('id'))
// { ok: true, value: Symbol('id'), issues: [] }
parseSymbol("id")
// { ok: false, value: null, issues: ["Value must be a symbol"] }
Notes
- This parser is intentionally strict: no coercion from strings or other types.
- For identifiers or keys, use parseString or parseNonEmptyString instead.