Search code examples
javascripttypescriptparametersabstract-class

What does (this:ClassName) parameter mean in TypeScript?


I am a newbie to TypeScript. I was confused what (this:ClassName) parameter of a function mean in an abstract class. For example:

abstract class Department{
   abstract describe(this:Department):void;
}

class ITDepartment extends Department{
    describe(){
        console.log('IT Department');
    }
}

As above, the implementing child class does not have any parameter for describe() method, but the parent class has the parameter of (this:Department). What is this code telling me and why does this code work??


Solution

  • welcome to SO.

    In TypeScript, if you've after a variable or parameter declaration a colon its defining the type of the given variable.
    In your case you're declaring the this variable as type Department.
    Normally you don't do this with class member functions, because the type of this is already known as the type of the class.