Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix tsc throwing errors for node typings?

I have started a new node project using typescript.

I installed typescript via:

$ npm install typescript@2 -g

My enviornment looks like this:

$ tsc -v
Version 2.0.0

$ node -v
v7.10.0

I installed the typings for node via:

npm install --save @types/node

I would expect:

tsc

to just run through without errors. Instead, I get errors in regards to the typings themselves:

366         isTTY?: true;
                    ~~~~

node_modules/@types/node/index.d.ts(366,17): error TS1110: Type expected.


1907         all?: false;
                   ~~~~~

node_modules/@types/node/index.d.ts(1907,15): error TS1110: Type expected.


1911         all: true;
                  ~~~~

node_modules/@types/node/index.d.ts(1911,14): error TS1110: Type expected.


1930         ttl: true;
                  ~~~~

node_modules/@types/node/index.d.ts(1930,14): error TS1110: Type expected.


4138     type DoesZapCodeSpaceFlag = 0 | 1;
                                     ~

node_modules/@types/node/index.d.ts(4138,33): error TS1110: Type expected.

My typescript will transpile anyways, yet I rather fix these errors. How to fix them?

like image 282
k0pernikus Avatar asked Sep 07 '25 03:09

k0pernikus


1 Answers

I was using an outdated tsc version. You may check if this is a problem via:

$ which tsc
/usr/local/bin/tsc

And it wasn't being updated by "npm install typescript -g" as those got installed to a path relative to my nvm.

Instead, I now use a local version of typescript for the project via:

npm install typescript --save

that will store the executable to:

$ ./node_modules/typescript/bin/tsc -v
Version 2.3.2

npm scripts looks for local binaries per default, hence I added the script in the package.json:

"scripts": {
    "console": "tsc && node dist/console.js",
},

so I can run just:

npm run console
like image 74
k0pernikus Avatar answered Sep 11 '25 02:09

k0pernikus