In my project, I have defined a class called BinarySearchTree
in a file named a.js
. This class has been exported and then imported into another file where it is used as the parent class for a different class called Traversal
.
However, I encountered an issue where the methods present in the parent class are not accessible in the child class. This results in an error message:
Error TS2339: Property 'getRootNode' does not exist on type 'Traversal'.
It's interesting to note that when I placed both classes in the same file, there were no errors.
Although I am comfortable with ES Standards, Typescript is relatively new to me. Please let me know if I missed any important details or if there is a workaround for this issue.
Here is the code snippet:
export class BinarySearchTree
{
root: any;
constructor()
{
// root of a binary seach tree
this.root = null;
}
getRootNode()
{
return this.root;
}
}
b.ts
import { BinarySearchTree } from './a.ts';
export class Traversal extends BinarySearchTree{
constructor()
{
super()
}
}
var _traversal = new Traversal();
_traversal.getRootNode()