简体   繁体   English

出现typeScript错误“模块,类,接口,枚举,导入或声明”

[英]typeScript error 'module, class, interface, enum, import or statement' expected

I'm trying to understand why this line invokes an error: 我试图理解为什么这一行会引发错误:

const value = 20 * 30;

error TS1008: Unexpected token; 错误TS1008:意外令牌; 'module, class, interface, enum, import or statement' expected. 预期为“模块,类,接口,枚举,导入或声明”。

any idea? 任何想法?

Here is the solution: 解决方法如下:

Earlier on my machine I had installed Visual Studio 2015 Pro Edition. 之前,我在计算机上安装了Visual Studio 2015 Pro Edition。 that had installed TypeScript 1.0.3.0. 已安装TypeScript 1.0.3.0。 and added its path to system environment. 并将其路径添加到系统环境。

Now I used npm install -g TypeScript and it did install, however from command line, typing tsc --version was always giving 1.0.3.0. 现在,我使用npm install -g TypeScript并成功安装,但是从命令行键入tsc --version始终提供1.0.3.0。

I removed the older path from environment and then restarted code and it worked fine. 我从环境中删除了较旧的路径,然后重新启动了代码,它工作正常。

Better you check your versions and the solution might help. 更好地检查版本,该解决方案可能会有所帮助。

It doesn't cause an error for me: https://jsfiddle.net/n0w1jt7b/ 它不会对我造成错误: https//jsfiddle.net/n0w1jt7b/

const value = 20 * 30; // 600

Be sure that all your versions are up-to-date. 确保所有版本都是最新的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JS错误(预期为类,接口或枚举) - JS Error (class,interface, or enum expected) 导入模块打字稿错误 - import module typescript error Typescript 接口 + 常量与 class 用于定义类似枚举的 object - Typescript interface + constants vs class for defining enum-like object 运行编译的 Javascript 代码时,TypeScript 文件中出现“语法错误:无法在模块外使用导入语句”错误 - "SyntaxError: Cannot use import statement outside of a module" error in a TypeScript file when running compiled Javascript code 另一个项目/模块的TypeScript导入类? - TypeScript import class from another project / module? 无法在后端使用 typescript 的模块外部使用导入语句 - Cannot use import statement outside a module using typescript on backend Typescript 与 mocha - 无法在模块外使用导入语句 - Typescript with mocha - Cannot use import statement outside a module Typescript & TypeORM:不能在模块外使用导入语句 - Typescript & TypeORM: Cannot use import statement outside a module TypeScript/Knex:不能在模块外使用 import 语句 - TypeScript/Knex: Cannot use import statement outside a module 不能在模块、Typescript、WebdriverIO 之外使用导入语句 - Cannot Use Import Statement Outside Module, Typescript, WebdriverIO
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM