typescript - tsc fel TS1110 node.d.ts Node.js v6.x


När jag kör tsc får jag många fel av formen

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

För din information: Den första raden i node.d.ts säger

// Typdefinitioner för Node.js v6.x

Vad är orsaken till dessa fel och hur åtgärdar man dem?

Steg för att reproducera: I en katalog som endast har filen tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "sourceMap": true,
        "module": "commonjs",
        "outDir": "."
    }
}

nästa, kör kommandot tsd install body-parser --save, utdata:

- 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

Katalogen har nu en underkatalog/typings.

Nästa kommando:

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.

Svar #1

TLDR;

npm install -g typescript

och inte

npm install -g tsc

Förklaring:

Jag märkte att Visual Studio 2015 inte har några problem med att kompilera samma katalog med TypeScript-filer, så jag undersökte byggloggen (med diagnostiknivå under Alternativ) och hittade denna rad:

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

Jag hade använt tsc-kompilatorn installerad med npm install tsc --global men dess version är 1.5.3 i dag, medan den som nämns ovan är version 1.8.9.

Relaterade artiklar