kristóf baján kristóf baján - 8 months ago 125
Node.js Question

TypeScript declare const from Node (fs, child_process etc.)

Basically my problem is that I have created a global constant variable for Node's FileSystem Api in JavaScript (!!! this is important) like so:

const FS = require('fs');

It is in fact working fine if after this in my TypeScript files I use this:

declare const FS;

But like this VSCode is not showing any kind of information when I type
except the fact that it exists. And why would it do so? (It's a separate file that is not even TypeScript)

Thanks to DefinetlyTyped I have though the declaration file for all of Node's modules.

So my question is:

Is there a way to reference my declared constant to Node's FileSystem via the declaration file?


This will let you use intellisense as you want

/// <reference path="../typings/globals/node/index.d.ts" />
import * as fs from "fs";

Also if not installed yes then install typing node with typings