Using Nodejs with Typescript


Question

I would like to use Nodejs in my typescript project and downloaded node.d.ts from https://github.com/borisyankov/DefinitelyTyped/tree/master/node

But VisualStudio finds a lot of errors in the .d.ts file. They're all basically the same:

Error 2 exported interface 'Server' extends interface from private module 'events' C:\Users\lhk\Desktop\typescript-game\strategy go\node\node-0.8.d.ts 236 37 node-0.8.d.ts

All the error messages complain that a private interface is extended.

I searched SO and found this question: nodejs require inside TypeScript file

One of the comments gives the advice to download node.d.ts from the Microsoft samples. I browsed the internet, found this article http://stackful.io/blog/typescript-nodejs-vim-and-linux-oh-my/ and downloaded the second version of node.d.ts , with the exact same result.

Where do I find a proper definitions file for nodejs and Typescript ?

1
11
5/23/2017 12:25:31 PM

Accepted Answer

For the 0.8.1-1 version of TypeScript, use the latest node.d.ts file from this github project: https://github.com/soywiz/typescript-node-definitions

I was getting the same exported interface errors until I pulled the latest definition files from there.

5
12/30/2012 2:39:19 AM

I'm not entirely sure what the heck is going on here.

I suspect that the current version of the (0.8.1~1) node.js package for Typescript broke some stuff. I've been running into this too. I tweaked the node.d.ts file and marked a couple things "export" instead of "declare" and that got me past my compilation issues, but I'm finding that the functions are not showing up in the current scope.

FWIW, I have been playing around with a personal fork of typescript-require and typescript-wrapper (both of which required some tweaking to work with 0.8.1~1) and I'm wasn't too certain that everything is working as well as it should be, so I wasn't sure that the issue is my issue or something endemic to the current node/typescript.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon