【问题标题】:Typescript: Syntax error. Unexpected token打字稿:语法错误。意外的标记
【发布时间】:2018-12-20 17:13:12
【问题描述】:

我正在尝试将 .ts 文件作为控制台应用程序启动。 将 .ts 文件转换为 .js(通过 tsc)后没有错误,但由于问题,我无法使用 ts-node 启动 .ts 文件:

“SyntaxError: Unexpected token ...”

我的 tsconfig.json 文件是

{
"compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "strict": true,
    "esModuleInterpop": rue
    }
} 

打字稿代码是

constructor(... pieces : IPiece[]){
super();
for (let i = 0; i < pieces.length; i++) {
    this.add(pieces[i]);
}}

所以我猜想 tsc 和 ts-node 编译 .ts 文件的方式不同。有任何想法吗?谢谢。

【问题讨论】:

  • ... 件:IPiece[] ?这是什么。

标签: typescript ts-node


【解决方案1】:

你的tsconfig.json文件代码有些拼写错误,

{
"compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "strict": true,
    "esModuleInterpop": rue // here change to true.
    }
} 

编辑:-

... pieces : IPiece[]

删除并添加privatepublic 类型到这个。

constructor(public pieces : IPiece[]){ } //use public or private

试试这个,然后告诉我。

【讨论】:

  • Interpop 听起来也有点可疑
  • 抱歉我听不懂
  • 互操作,互操作性
  • 修复了 tsconfig.json。结果相同
  • 谢谢!这真的很有帮助!现在它抱怨“意外的保留字”打字稿代码是从“typescript-dotnet-es6/System/Collections/List”导入{List}有什么想法吗?再次感谢!
猜你喜欢
  • 2019-05-25
  • 2021-08-11
  • 2019-10-26
  • 1970-01-01
  • 2013-09-04
  • 1970-01-01
  • 1970-01-01
  • 2015-05-28
相关资源
最近更新 更多