cannot redeclare block scoped variable (typescript)

问题:


image.png

解决方案:
在每个ts文件的开头添加:
export {};
就解决了 ^^

官方的解释:
Typescript is moduler and each module has it’s own block. So, basically if you could somehow enclose the variable which is declared as let within it’s own module, the error will be resolved because now your let variable is in it’s separate block.

To achieve this, simply type export on the top of your script or additionally you can type export {}. Now you will see that the error is resolved.

蹩脚翻译:
Typescript是模块化的,同时每个模块都有自己的代码块。所以,基本上在一定程度上let可以让所有的变量都
在一个模块中。如果你把变量放到单独的代码块中,那么问题将很快被解决。

要实现这个,只要在你的脚本顶部写下export{}。现在你将看到问题已经被解决了。

image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容