I have a class BinarySearchTree
in a file ( a.js
) which I've exported then imported BinarySearchTree
in other file and use it as a parent class for one of other class Traversal
.(我在导出的文件( a.js
)中有一个BinarySearchTree
类,然后在其他文件中导入BinarySearchTree
并将其用作其他类Traversal
的父类。)
The issue, I felt is that the method present in the parent class is not accessible in the child class (throws error as :(我感到的问题是,父类中存在的方法无法在子类中访问(引发错误为:)
error TS2339: Property 'getRootNode' does not exist on type 'Traversal'.(错误TS2339:类型“ Traversal”上不存在属性“ getRootNode”。)
Note: I tried keeping both the class in the same file and it works without error.(注意:我尝试将两个类都放在同一文件中,并且可以正常工作。)
I'm new to Typescript but well versed with ES Standards.(我是Typescript的新手,但精通ES标准。) Please highlight, If i'm missing any details here or if there is a work around.(请突出显示,如果我在这里缺少任何详细信息或有解决方法。)
Code Segment: a.ts(代码段: a.ts)
export class BinarySearchTree
{
root: any;
constructor()
{
// root of a binary seach tree
this.root = null;
}
getRootNode()
{
return this.root;
}
}
b.ts(b.ts)
import { BinarySearchTree } from './a.ts';
export class Traversal extends BinarySearchTree{
constructor()
{
super()
}
}
var _traversal = new Traversal();
_traversal.getRootNode()
ask by SJC translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…