【发布时间】:2019-12-04 01:31:31
【问题描述】:
我正在尝试做这样的事情:
import * as d3 from 'd3-scale-chromatic'
const selectColor = (
decimal: number,
colorScheme: string = 'interpolateRainbow'
): string =>
d3[colorScheme](decimal)
但我收到了这个 TS 错误:
元素隐式具有“any”类型,因为“string”类型的表达式不能用于索引类型“typeof import("PATH_TO_MODULES/node_modules/@types/d3-scale-chromatic")”
我认为我基本上想用以下方式扩展我正在导入的类型:
interface d3 {
[key: string]: (number) => string
}
【问题讨论】:
标签: d3.js typescript-typings typescript2.0 typescript-generics