Highcharts TypeScript – 类型 ‘typeof import’ 上不存在属性 ‘RangeSelector’

huangapple go评论98阅读模式
英文:

Highcharts TypeScript - Property 'RangeSelector' does not exist on type 'typeof import'

问题

"我想在TypeScript中原型化drawInput Highcharts函数,当我尝试这样做时:

(function (H) {
    Highcharts.RangeSelector.prototype.drawInput = () => {
        // 一些代码
    };
})(Highcharts);

它会显示"Property 'RangeSelector' does not exist on type 'typeof import'"。

我尝试了以下方法:

(function (H) {
    console.log(Highcharts.RangeSelector)
})(Highcharts as any);

它返回undefined。奇怪的是,当我只是这样做时:

console.log(Highcharts)

它显示了RangeSelector选项。"

英文:

I want to prototype the drawInput Highcharts function in TypeScript and when I want to do:

(function (H) {
    Highcharts.RangeSelector.prototype.drawInput = () => {
        // some code
    };
})(Highcharts);

it says that "Property 'RangeSelector' does not exist on type 'typeof import'"

I tried to do the following:

(function (H) {
    console.log(Highcharts.RangeSelector)
})(Highcharts as any);

and it returned undefined. Strange is that when I simply do the

console.log(Highcharts)

it shows the RangeSelector option

答案1

得分: 0

Just cast the Highcharts object as any:

(function (H) {
console.log((H as any).RangeSelector);
(H as any).RangeSelector.prototype.drawInput = () => {
// some code
};
})(Highcharts);

https://codesandbox.io/s/highcharts-typescript-rangeselector-68zhz2

英文:

Just cast the Highcharts object as any:

(function (H) {
  console.log((H as any).RangeSelector);
  (H as any).RangeSelector.prototype.drawInput = () => {
    // some code
  };
})(Highcharts);

https://codesandbox.io/s/highcharts-typescript-rangeselector-68zhz2

huangapple
  • 本文由 发表于 2023年6月27日 19:16:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76564310.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定