如何在打字稿中导入/要求标准节点模块?
how to import / require standard node modules in typescript?
将 require
与打字稿和标准 NPM 模块一起使用的最佳方式是什么?
我正在尝试使用 debug
包。
我已经从 npm 安装
还有 tsd install debug
但是,相同的语法在一个文件中是可以的,但在另一个文件中则不行。
我想这是一个加载顺序的事情,TS 认为我正在重新声明一个变量?
let debug = require("debug")("async-test");
# ReferenceError: debug is not defined
debug = require("debug")("async-test");
# ReferenceError: debug is not defined
left/right 面板(不同文件)上的相同代码将显示 error/not。
What is the best way to use require with typescript and standard NPM modules?
试试 typings
。它有很棒的 debug
定义 https://github.com/typed-typings/npm-debug。
npm install typings -g
typings install debug
然后设置您的 tsconfig.json
:https://github.com/typings/typings#maindts-and-browserdts
现在你可以做:
import debug = require('debug')
完全类型安全
将 require
与打字稿和标准 NPM 模块一起使用的最佳方式是什么?
我正在尝试使用 debug
包。
我已经从 npm 安装
还有 tsd install debug
但是,相同的语法在一个文件中是可以的,但在另一个文件中则不行。 我想这是一个加载顺序的事情,TS 认为我正在重新声明一个变量?
let debug = require("debug")("async-test");
# ReferenceError: debug is not defined
debug = require("debug")("async-test");
# ReferenceError: debug is not defined
left/right 面板(不同文件)上的相同代码将显示 error/not。
What is the best way to use require with typescript and standard NPM modules?
试试 typings
。它有很棒的 debug
定义 https://github.com/typed-typings/npm-debug。
npm install typings -g
typings install debug
然后设置您的 tsconfig.json
:https://github.com/typings/typings#maindts-and-browserdts
现在你可以做:
import debug = require('debug')
完全类型安全