以下是示例代码,当类'exposedMethod'
中引用类'First'
时,智能感知似乎无法识别'Second'
。
Intellisense是否支持此功能,还是我遗漏了某些内容?
class First{
exposedMethod=()=>{
}
}
class Second{
firstClass;
constructor(firstClass:First)
{
firstClass = firstClass;
}
someFunction=()=>{
this.firstClass.exposedMethod(); //No intellisense support here
}
}
答案 0 :(得分:3)
您应该向会员添加类型
class Second{
// instead of this
// firstClass;
// we should use this
firstClass:First; // here
constructor(firstClass:First)
{
// here we should assign this.firstClass
this.firstClass = firstClass;
}
但是,我认为最合适的方法是使用TS编译器附带的一些语法糖
class Second{
// this syntax (protected, private, public) will do behind the same as above
constructor(protected firstClass:First)
{
}