Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
Add new well-known symbol property like Symbol.myProperty in TypeScript

In JavaScript we have global symbol on the Symbol object, such as Symbol.iterator and Symbol.match.

I can assign the property by erasing the type to any, however TypeScript doesn’t recognise it.

// Define Symbol.hello
(Symbol as any).hello = Symbol("hello");

// Try using it later:
Symbol.hello;
// TypeScript error: Property 'hello' does not exist on type 'SymbolConstructor'.ts(2339)

How do I add my property to Symbol in a way that makes TypeScript happy?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can declare your property on the SymbolConstructor interface:

declare global {
  interface SymbolConstructor {
      readonly hello: symbol;
  }
}

You can now define your property:

// Define Symbol.hello
(Symbol as { hello: symbol }).hello = Symbol("hello");

// TypeScript is now happy:
Symbol.hello;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!