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

371
Views
Typescript: Can't return child class instance from super class' function

I'm having trouble returning a child class object from a super class function. I have the following structure:

pizza.ts:

import { PineapplePizza } from './pineapple.pizza';

export class Pizza {
    public putOn(Pineapple pineapple): Pizza {
        // ...
        return new PineapplePizza(pineapple);
        // ...
    }
}

pineapple.pizza.ts:

import { Pizza } from './pizza';

export class PineapplePizza extends Pizza {
    // ...
}

But I keep getting this runtime error:

firefox:

ReferenceError: can't access lexical declaration 'Pizza' before initialization

chrome:

ReferenceError: 'Pizza' is not defined

Does anyone know how to fix that? Or is impossible to return a child class instance from a super class?

EDIT #1:

This might be due to circular importing. Is there a way to pre-declare a class, kind of like with c++? Or a way to control which file gets compiled first?

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!