使用TypeScript编写node项目的疑惑
 发布于 9 年前  作者 louislve  14055 次预览  最后一次回复是 9 年前  来自 问答 

请问怎么在.ts中引用node系统库呢,如http、fs等,没有他们的d.ts啊

import http = require(“http”)
ts编译时候报错Cannot find module ‘http’

ps: 如果是常用的第三方库,webstorm里面有集成,找到对应的d.ts加上就好了 /// <reference path="…/…/libs/underscore.browser.d.ts"/>

7 回复
hellopao
npm install typings -g

typings init
typings install node --ambient --save

你搜下typings

louislve

@hellopao

typings install http --ambient --save typings ERR! message Unable to find “http” for “dt” in the registry

我在webstorm里面也找了,没有http的dt, 其他的node系统库也没有,怎么破?

hellopao

@louislve , httpnode里的,你装node就行了

louislve

@hellopao 但是编译ts的时候提示找不到http啊,而且没有代码提示。

hellopao

@louislve 检查下node.d.ts是不是正确安装,webstorm我没用过,不知道是怎么引用.d.ts的,你可以把下载下来的node.d.ts放到指定目录,ts文件里的referencepath指向那个地址就好。httpnode里的,你装了node.d.ts就有。

louislve

@hellopao 可以了,谢谢你