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

268
Views
Typescript abstract method doesn't inherit the params type

I have the following code:

abstract class Foo<T extends { data: string }> {
  abstract doSomething(params: T): void;
} 


class Baz extends Foo<{ id: string; data: string }> {
   doSomething(params) {}
}

My expectation is that when implementing the doSomething method it'll automatically infer the params as T, but it infers it as any. Am I wrong?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

By extending, the compiler just checks whether the derived class is assignable to the base class, you are free to design the derived class as long as it is assignable to the base class.

Imagine you are not extending, just writing a regular class. doSomething(param) does implicitly means doSomething(param:any). This implication dose not change even when you are extending. Since (any) => void is assignable to ({ id: string; data: string }) => void , everything is fine. The compiler won't do extra work.

over 4 years ago · Santiago Trujillo 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!