【发布时间】:2020-01-09 23:56:32
【问题描述】:
我有一个使用 TypeScript 和 d3 的项目。我已经安装了 'd3'、'@types/d3' 并像这样使用 d3:
import * as d3 from 'd3';
const x = d3.scaleLinear ...
在我想使用未在当前“@types/d3-selection”中声明的d3.scaleSymlog 之前,它运行良好。
我尝试扩充“d3-selection”模块:
declare module 'd3-selection' {
export function scaleSymlog(...);
}
但是在这样做之后,我的代码中使用的 'd3-selection' 甚至其他 d3 子模块中的所有符号现在都找不到了:
Property 'mouse' does not exist on type 'typeof import("<project>/frontend/node_modules/@types/d3/index")'.
TypeScript 文档说:
You can’t declare new top-level declarations in the augmentation – just patches to existing declarations.
那么,我该如何正确声明和使用scaleSymlog?
【问题讨论】:
标签: typescript d3.js typescript-typings