TypeScript从Node声明const(fs,child_process等)

时间:2021-10-17 15:30:24

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

基本上我的问题是我在JavaScript中为Node的FileSystem Api创建了一个全局常量变量(!!!这很重要),如下所示:

const FS = require('fs');

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

它实际上工作正常,如果在我的TypeScript文件中,我使用它:

declare const FS;

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

但是,当我键入FS时,VSCode没有显示任何类型的信息,除了它存在的事实。为什么会这样呢? (这是一个单独的文件,甚至不是TypeScript)

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

感谢DefinetlyTyped,我有所有Node模块的声明文件。

So my question is:

所以我的问题是:

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

有没有办法通过声明文件将我声明的常量引用到Node的FileSystem?

1 个解决方案

#1


1  

This will let you use intellisense as you want

这将让您根据需要使用intellisense

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

Also if not installed yes then install typing node with typings

如果没有安装yes,则安装带打字的输入节点

#1


1  

This will let you use intellisense as you want

这将让您根据需要使用intellisense

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

Also if not installed yes then install typing node with typings

如果没有安装yes,则安装带打字的输入节点