目前,我使用TypeScript,遇到了使用谷歌无法自行解决的功能(?)。有人能说清楚吗?奇怪的是关于明确
this
类方法的声明。我查看了转译的javascript,看到了第一个参数(
这
)是无效的。所以代码实际上是有效的。但我想知道这是什么,为什么会这样?
class Foo {
bar(this: Foo, whatever: any) {
console.log(whatever);
}
};
...
const foo = new Foo();
foo.bar({ baz: 'it works properly' });