这是一个故意改变的行为吗?
TypeScript 版本: 3.4.0-dev.20190809搜索词:代码
import assert from 'power-assert';declare global { const assert: typeof assert;}
import assert from 'power-assert';
declare global {
const assert: typeof assert;
}
预期行为:
循环引用错误。
实际行为:
没有错误。
Playground 链接:相关问题:
okxuctiv1#
之前发生了什么?
ac1kyiln2#
循环引用错误。因此,我必须避免冲突,如下所示:https://github.com/falsandtru/spica/blob/v0.0.269/global.test.d.ts#L3因此,以下代码可以正确地避免错误。
import assert from 'power-assert';declare const assert: typeof assert;
declare const assert: typeof assert;
全局模块声明省略此错误。
2w3rbyxf3#
我们可以看到VSCode很混乱:转到定义命令将我们从typeof assert带到const assert,在全局模块声明中,但其实际定义是在另一个模块(文件)中定义的。
typeof assert
const assert
3条答案
按热度按时间okxuctiv1#
之前发生了什么?
ac1kyiln2#
循环引用错误。因此,我必须避免冲突,如下所示:
https://github.com/falsandtru/spica/blob/v0.0.269/global.test.d.ts#L3
因此,以下代码可以正确地避免错误。
全局模块声明省略此错误。
2w3rbyxf3#
我们可以看到VSCode很混乱:转到定义命令将我们从
typeof assert
带到const assert
,在全局模块声明中,但其实际定义是在另一个模块(文件)中定义的。