Type guard that checks if a value is a symbol.
Type Narrowing Behavior:
unknown
symbol
true
Symbol()
The value to check
true if u is a symbol, false otherwise. When true, TypeScript narrows the type to symbol.
u
false
const id = Symbol('id');const shared = Symbol.for('shared');const tokens: unknown[] = [id, 'shared', shared];const symbols = tokens.filter(isSymbol);assert.deepStrictEqual(symbols, [id, shared]); Copy
const id = Symbol('id');const shared = Symbol.for('shared');const tokens: unknown[] = [id, 'shared', shared];const symbols = tokens.filter(isSymbol);assert.deepStrictEqual(symbols, [id, shared]);
Type guard that checks if a value is a symbol.
Type Narrowing Behavior:
unknown
tosymbol
whentrue
Symbol()
constructor