Typescript 为什么可以';我不能使用这个内部函数吗?

Typescript 为什么可以';我不能使用这个内部函数吗?,typescript,typescript-decorator,Typescript,Typescript Decorator,代码: 错误: const f: any = function(...args: any[]) { const a = this; }; 您启用了noimplicitt此编译器选项,并且在新的f函数中,此表达式隐式包含类型any——因此出现错误 要解决此问题,只需使用以下命令显式指定类型: 默认情况下,函数中的类型为any。从TypeScript 2.0开始,您可以为该参数提供一个显式表达式。此参数是假参数,在函数的参数列表中位于第一位 您启用了noimplicitt此编译器选项,并且

代码:

错误:

const f: any = function(...args: any[]) {
    const a = this;
};

您启用了
noimplicitt此
编译器选项,并且在新的
f
函数
中,此
表达式隐式包含类型
any
——因此出现错误

要解决此问题,只需使用以下命令显式指定类型:

默认情况下,函数中的类型为any。从TypeScript 2.0开始,您可以为该参数提供一个显式表达式。此参数是假参数,在函数的参数列表中位于第一位


您启用了
noimplicitt此
编译器选项,并且在新的
f
函数
中,此
表达式隐式包含类型
any
——因此出现错误

要解决此问题,只需使用以下命令显式指定类型:

默认情况下,函数中的类型为any。从TypeScript 2.0开始,您可以为该参数提供一个显式表达式。此参数是假参数,在函数的参数列表中位于第一位


@ritaj这不是在箭头函数中…@ritaj这不是在箭头函数中。。。
semantic error TS2683 'this' implicitly has type 'any' because it does not have a type annotation.
const f: any = function(this: typeof target, ...args: any[]) {
    // ...
};