简体   繁体   中英

how to use @types/node in node application

I am working in VSCode on Ubuntu 16.04. I've created node project using below commads:

npm init
tsc --init

I've created a new file called index.ts . I'm trying to use fs and readling to read file contents. but when I am writing below lines of code at the top of index.d.ts :

import fs = require('fs');
import readline =  require('readline');

I'm getting below error: can not find module 'fs' and can not find module 'readline'

even process is not found. I've installed typings of node from here using below command:

sudo npm install @types/node -global --save

Can anyone please help me how to resolve this error?

从TypeScript 2.x开始,所有类型都使用npm安装,如下所示: npm install @types/node

For TypeScript 1.8, it might be better to typings to install the node types. For detail see the quickstart at: https://basarat.gitbooks.io/typescript/content/docs/quick/nodejs.html .

For what i know you have two options here:

  1. (Recommended) Install devDepencencie npm install @types/node --save-dev , which will add the type module for http.
  2. Create a index.d.ts file declaring a definition for http module, like: declare module 'http . This method will not enable auto-complete for http methods

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM