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

367
Views
How to inherit from a class but also infer custom properties

When I have an object of known type and want to add some properties to it. And I'm also too lazy to write an additional interface.

How can I get both inherited and infered types for properties on the same object?

For example, express adds properties to the request object and I want to do the same

import * as http from 'http';

/**
 * @param {http.IncomingMessage} request
 * @param {http.ServerResponse} response
 */
function doStuff(request, response) {
  request.numericProp = 10;

  console.log(request.numericProp + 20);
}

Here I see errors at .numericProp

Property 'numericProp' does not exist on type 'IncomingMessage'.ts(2339)

Of course, I can allow any additional props by doing this:

/**
 * @param {http.IncomingMessage & { [key: string]: any }} request
 * @param {http.ServerResponse} response
 */

And there will be no more errors while I still can see hints about IncomingMessage properties, BUT.. numericProp is any.

I want it to be automatically infered as number.

Is there any built-in trick, like Partial<>, or what kind of construction can I use?

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!