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

119
Views
Explicitly apply decorator after defineProperty

I have typescript code with "experimentalDecorators": true which allows me to apply decorators.

Also I'm using mobx witch has decorators like observable, computed and so on.

Some properties in my code are generated dynamically and I want to apply decorators to them too.

In following code

class Smth {
  @observable first = 0;
  declare second: number;

  constructor(
    getSecond: () => number,
  ) {
    Object.defineProperty(this, "second", { get: getSecond, configurable: true });

    makeObservable(this);
  }
}

I want to do something near this call

Object.defineProperty(this, "second", { get: getSecond, configurable: true });

so that it would behave like

@computed get second() { /* ... */ }

How can I apply computed decorator after I used defineProperty?

about 4 years ago · Juan Pablo Isaza
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!