打字稿:对引用的类没有智能感知支持

时间:2015-09-29 09:11:45

标签: visual-studio typescript intellisense

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

Intellisense是否支持此功能,还是我遗漏了某些内容?

class First{
    exposedMethod=()=>{

    }
}

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

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

1 个答案:

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