Shyamal Parikh
Shyamal Parikh

Reputation: 3068

Typescript: No intellisense support for referenced class

Following is an example code, it seems that intellisense doesn't recognize the 'exposedMethod' when the class 'First' is referenced in class 'Second'.

Is this not supported by Intellisense or am I missing something?

class First{
    exposedMethod=()=>{

    }
}

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

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

Upvotes: 1

Views: 87

Answers (1)

Radim Köhler
Radim Köhler

Reputation: 123861

You should add a type to your member

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;
    }

But the most suitable way, I'd say, is to use some syntax sugar coming with TS compiler

class Second{
    //  this syntax (protected, private, public) will do behind the same as above
    constructor(protected firstClass:First)
    {
    }

Upvotes: 3

Related Questions