Dev Helpers
← Back

Narrow an unknown symbol

Narrow an unknown symbol using TypeScript.

Open this example in the interactive library

Source code

const samples: unknown[] = [null, "Ada", 12, { id: 1 }, [2, 3], true];
console.log(
  ((v: unknown) => (typeof v === "symbol" ? v.description : undefined))(
    Symbol("job"),
  ),
);

Sample output

job