打字稿:不支持对引用 class 的智能感知

Typescript: No intellisense support for referenced class

以下是示例代码,当 class 'First' 在 class 'Second' 中引用时,智能感知似乎无法识别 'exposedMethod' .

这是 Intellisense 不支持还是我遗漏了什么?

class First{
    exposedMethod=()=>{

    }
}

class Second{
    firstClass;
    constructor(firstClass:First)
    {
        firstClass = firstClass;
    }

    someFunction=()=>{
        this.firstClass.exposedMethod();    //No intellisense support here
    }
}

您应该为您的会员添加类型

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)
    {
    }