Quantcast
Channel: Node.js Tools for Visual Studio
Viewing all articles
Browse latest Browse all 4630

Commented Unassigned: Node.js with TypeScript: calling node.js function instead of standard [984]

$
0
0
please help me with the following problem. I created default node.js app with express using Visual Studio nodejs tools and now I'm trying to call setTimeout function that is declared in node.d.ts. The code is like this:

```
var timer: NodeTimer;
timer = setTimeout(somecallback, 1000);
```
But the code doesn't compile saying 'Cannot convert 'Number' to 'NodeTimer''

As I understand, the problem is that it takes standard setTimeout function instead of taking the one from node.d.ts.

I tried specifying the reference to node.d.ts with \\\<reference> tag - this doesn't help. How can I state explicitly that I want to use setTimeout from node.d.ts?
Comments: node.d.ts is referenced by default - without it you wouldn't be seeing completions for node standard modules like 'fs'. I can repro this problem, but it also repros without NTVS in the picture - e.g. running tsc.exe directly from command line on the same code: ``` C:\Projects\NodejsConsoleApp4>tsc app.ts Scripts\typings\node\node.d.ts C:/Projects/NodejsConsoleApp4/app.ts(2,1): error TS2012: Cannot convert 'number' to 'NodeTimer': Type 'Number' is missing property 'ref' from type 'NodeTimer'. ``` So this is not an NTVS bug (curiously enough, if you do "Go To Definition" on setTimeout in NTVS, it will actually navigate to the correct definition!). I'm not sure whether this is a bug in the TS compiler itself, or a bug in node.d.ts, or whether it's really by (not particularly nice) design.

Viewing all articles
Browse latest Browse all 4630

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>