tsc错误TS1110 node.d.ts Node.js v6.x

时间:2016-06-14 19:18:40

标签: node.js typescript tsc

运行tsc时,表格中出现了很多错误

typings/node/node.d.ts(Ln,Col): error TS1110: Type expected.

仅供参考:node.d.ts的第一行说

  

// Node.js v6.x的类型定义

这些错误的原因是什么以及如何解决?

重现的步骤: 在只有文件tsconfig.json

的目录中
{
    "compilerOptions": {
        "target": "es5",
        "sourceMap": true,
        "module": "commonjs",
        "outDir": "."
    }
}

接下来,执行命令tsd install body-parser --save,输出:

- body-parser                  / body-parser
  -> express                   > express
  -> serve-static              > serve-static
  -> express-serve-static-core > express-serve-static-core
  -> node                      > node
  -> mime                      > mime

> running install..

> written 6 files:

   - body-parser/body-parser.d.ts
   - express-serve-static-core/express-serve-static-core.d.ts
   - express/express.d.ts
   - mime/mime.d.ts
   - node/node.d.ts
   - serve-static/serve-static.d.ts

该目录现在具有子目录/typings

下一个命令:

$ tsc
typings/node/node.d.ts(87,23): error TS1110: Type expected.
typings/node/node.d.ts(244,57): error TS1110: Type expected.
typings/node/node.d.ts(245,48): error TS1110: Type expected.
typings/node/node.d.ts(246,50): error TS1110: Type expected.
typings/node/node.d.ts(247,60): error TS1110: Type expected.
typings/node/node.d.ts(248,45): error TS1110: Type expected.
typings/node/node.d.ts(249,37): error TS1110: Type expected.
typings/node/node.d.ts(291,57): error TS1110: Type expected.
typings/node/node.d.ts(292,48): error TS1110: Type expected.
typings/node/node.d.ts(293,50): error TS1110: Type expected.
typings/node/node.d.ts(294,60): error TS1110: Type expected.
typings/node/node.d.ts(295,45): error TS1110: Type expected.
typings/node/node.d.ts(496,54): error TS1110: Type expected.
typings/node/node.d.ts(540,57): error TS1110: Type expected.
typings/node/node.d.ts(541,48): error TS1110: Type expected.
typings/node/node.d.ts(542,50): error TS1110: Type expected.
typings/node/node.d.ts(543,61): error TS1110: Type expected.
typings/node/node.d.ts(544,65): error TS1110: Type expected.
typings/node/node.d.ts(545,60): error TS1110: Type expected.
typings/node/node.d.ts(546,45): error TS1110: Type expected.
typings/node/node.d.ts(547,37): error TS1110: Type expected.
typings/node/node.d.ts(869,35): error TS1110: Type expected.
typings/node/node.d.ts(1950,52): error TS1005: '=' expected.
typings/node/node.d.ts(1951,76): error TS1005: '=' expected.
typings/node/node.d.ts(1952,52): error TS1005: '=' expected.
typings/node/node.d.ts(1952,96): error TS1005: '=' expected.
typings/node/node.d.ts(1962,54): error TS1005: '=' expected.
typings/node/node.d.ts(1963,74): error TS1005: '=' expected.
typings/node/node.d.ts(1964,54): error TS1005: '=' expected.
typings/node/node.d.ts(1964,94): error TS1005: '=' expected.

1 个答案:

答案 0 :(得分:5)

<强> TLDR;

npm install -g typescript

而不是

npm install -g tsc

<强>解释

我注意到Visual Studio 2015在编译TypeScript文件的同一目录时没有问题所以我检查了构建日志(在Options下有Diagnostic verbosity)并找到了这一行:

C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe  --module CommonJS --sourcemap --target ES5 --noEmitOnError --locale en-US 

我一直在使用npm install tsc --global安装的tsc编译器,但截至今天它的版本是1.5.3,而上面提到的是版本1.8.9。