TypeScript 类/接口方法中的显式“this”参数

问题描述

现在我使用 TypeScript 并遇到功能(?)我无法通过使用 Google 自己弄清楚。任何人都可以说清楚吗?奇怪的是关于类方法的显式 this 声明。我查看了转译的 javascript,发现第一个参数 (this) 是无效的。所以代码实际上有效。但我想知道这是什么以及为什么会这样?

class Foo {
    bar(this: Foo,whatever: any) {
        console.log(whatever);
    } 
};

...

const foo = new Foo();
foo.bar({ baz: 'it works properly' });

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)