Avatar ·

使用ES2015模块时出现错误“requires an imported helper but module 'tslib' cannot be found”

大家好!我是TypeScript新手,正在尝试配置一个项目。我有一个简单的index.ts文件,代码如下: ```typescript class User { constructor(public name: string, public age: number) {} greet() { return `你好,我叫${this.name}`; } } const user = new User("安娜", 25); console.log(user.greet()); ``` 在我的tsconfig.json中,我指定了: ```json { "compilerOptions": { "target": "ES5", "module": "ES2015", "outDir": "./dist", "strict": true } } ``` 当我通过`tsc`运行编译时,出现了以下错误: ``` error TS2802: This syntax requires an imported helper but module 'tslib' cannot be found. ``` 我搜索了这个错误,但不太明白“imported helper”是什么意思,以及为什么它与tslib相关。我没有安装任何额外的包,只有TypeScript本身。你能解释一下问题所在以及如何修复吗?为什么这个错误在使用ES2015模块时会出现?