Typescript circular reference problem

there are two classes as follows

// Parent.ts
import {Sub} from "./Sub";

export class Parent {
   public getSub() {
        return new Sub();
    }
}
// Sub.ts
import {Parent} from "./Parent";

export class Sub extends Parent {}

running js after ts compilation throws an error

Uncaught TypeError: Object prototype may only be an Object or null: undefined

it seems that the ts compiler defines the Sub class first when it sees a reference to the Sub class in the Parent class, and before the Parent class is defined, it will cause Parent to throw a TypeError. for the undefined,

.

how can I change it to let the ts compiler define Parent first

Feb.28,2021
Menu