我想在assert
/ browserify
个捆绑包中使用tsify
模块。请参阅https://www.npmjs.com/package/assert和https://github.com/substack/browserify-handbook#builtins以及https://nodejs.org/api/assert.html。简而言之,它是浏览器中与node-js兼容的assert
模块,即内置浏览器。
所以我在@types/assert
添加了package.json
。但是声明模块无法识别(似乎有些错误)。所以我想做一个等同于node_modules/@types/assert
但在node_modules
之外的node_modules
不应该在源代码控制中。
有可能吗?如果没有,可以/应该使用/// <reference
老派语法或declare module "assert"
或什么?
答案 0 :(得分:0)
声明模块乍一看对我来说没问题(没有彻底的测试),但无论如何,假设你在谈论this library
创建一个将在源代码管理下的typings/assert/assert.d.ts
目录/ subdir /文件
必须将assert.d.ts
构造为外部模块定义,该定义导出单个符号assert
。内容几乎是@ types / assert中找到的内容的直接副本(带有您提到的所需更正)
declare module 'assert' {
function assert(value:any, message?:string):void;
namespace assert {
export function fail(actual?:any, expected?:any, message?:string, operator?:string):void;
...
}
export = assert
}
在tsconfig.json
中的,只需确保编译中包含(即不排除)typings
目录的内容。
答案 1 :(得分:0)
澄清@Bruno Grieder的答案。
tsc
.d.ts
如何查找declare module 'assert'
个文件
puts @image.map { |inner| inner.join ' ' }.join $/
#⇒ 0 0 0 0
# 0 1 0 0
# 0 0 0 1
# 0 0 0 0
的机制称为环境模块:
https://www.typescriptlang.org/docs/handbook/module-resolution.html