(this:ClassName) 参数在 TypeScript 中是什么意思?

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

我是 TypeScript 的新手。 我很困惑函数的 (this:ClassName) 参数在抽象 class 中的含义。 例如:

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

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

如上,实现子 class 没有 describe() 方法的任何参数,但父 class 具有 (this:Department) 的参数。这段代码告诉我什么,为什么这段代码有效??

欢迎来到 SO。

在 TypeScript 中,如果您在变量或参数声明之后有一个冒号,则它定义给定变量的类型。
在您的情况下,您将 this 变量声明为 Department.
类型 通常你不会用 class 成员函数这样做,因为 this 的类型已经被称为 class 的类型。