Avatar ·

TypeScript中实验性装饰器的警告

大家好!我是TypeScript新手,正在尝试使用装饰器为我的类添加日志功能。我安装了Visual Studio Code,并创建了一个包含tsconfig.json文件的简单项目。这是我的代码: ```typescript function log(target: any, propertyKey: string, descriptor: PropertyDescriptor) { const originalMethod = descriptor.value; descriptor.value = function(...args: any[]) { console.log(`方法 ${propertyKey} 被调用,参数为:`, args); return originalMethod.apply(this, args); }; return descriptor; } class Calculator { @log add(a: number, b: number): number { return a + b; } } const calc = new Calculator(); calc.add(2, 3); ``` 编译时我收到警告:“Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.” 我尝试添加 `"experime