Type Definitions file for d3-scale模块中有以下代码。
export interface ScaleLinear<Range, Output> {
(value: number | { valueOf(): number }): Output;
/**
* Important: While value should come out of range R, this is method is only applicable to
* values that can be coerced to numeric. Otherwise, returns NaN
*/
invert(value: number | { valueOf(): number }): number;
domain(): Array<number>;
domain(domain: Array<number | { valueOf(): number }>): this;
range(): Array<Range>;
range(range: Array<Range>): this;
/**
* Important: While value should come out of range R, this is method is only applicable to
* values that can be coerced to numeric.
*/
rangeRound(range: Array<number | { valueOf(): number }>): this;
clamp(): boolean;
clamp(clamp: boolean): ScaleLinear<Range, Output>;
interpolate(): InterpolatorFactory<any, any>;
interpolate(interpolate: InterpolatorFactory<Range, Output>): this;
interpolate<NewOutput>(interpolate: InterpolatorFactory<Range, NewOutput>): ScaleLinear<Range, NewOutput>;
ticks(count?: number): Array<number>;
tickFormat(count?: number, specifier?: string): ((d: number | { valueOf(): number }) => string);
nice(count?: number): this;
copy(): ScaleLinear<Range, Output>;
}
我对界面名称后的尖括号<Range, Output>
感到困惑!我在TypeScript上观看了PluralSight课程,并没有提到这种语法。
更重要的是,当我尝试在我自己的代码中使用它时,VS Code告诉我:
我知道我的/// ref<>
和import
陈述的方式是正确的,因为它不会抱怨其他内容(例如d3Scale.ScalePoint<string>
)
我做错了什么?任何澄清将不胜感激。