如何在 VS Code 中使用 JavaScript 私有字段? [英] How can I use JavaScript private fields in VS Code?
问题描述
我在我的文档中使用了
具体的错误是:无效字符.ts(1127)
如何让 VS Code 理解私有字段?
原因
VS Code 使用 TypeScript 项目 来支持其 JavaScript 和 TypeScript IntelliSense.TypeScript 项目仅在 TypeScript 3.8 中添加了对私有字段的支持.然而,当前版本的 VS Code (1.41) 仅包含最新的稳定版 TypeScript 3.7.
如果您看到私有字段的语法错误,则您很可能在 VS Code 中使用了尚不理解私有字段的 TypeScript 版本.
解决方法
VS Code 1.43(将于 2020 年 3 月上旬发布)将包含 TypeScript 3.8.在此之前,您可以通过以下任一方式升级您的工作区以使用更新的打字稿版本:
请记住,其他 VS Code 扩展(例如 linter)可能也需要更新以支持私有字段
I'm using the proposed private field syntax in my JavaScript but VS Code says this is a syntax error:
The specific error is: Invalid character. ts(1127)
How can I make VS Code understand private fields?
Cause
VS Code uses the TypeScript project to power both its JavaScript and TypeScript IntelliSense. The TypeScript project only added support for private fields in TypeScript 3.8. However the current release of VS Code (1.41) only includes the latest stable TypeScript 3.7 release.
If you see syntax errors for private fields, you are likely using a version of TypeScript in VS Code that does not yet understand private fields.
Workaround
VS Code 1.43 (to be released early March 2020) will include TypeScript 3.8. Until then, you can upgrade your workspace to use a newer typescript version by either:
Installing this extension
Following these instructions
Keep in mind that other VS Code extensions—such as linters—may also need to be updated with support for private fields
这篇关于如何在 VS Code 中使用 JavaScript 私有字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!