highcharts/highcharts.d.ts file in this repo and had problems.Hi,
I installed the typings for highcharts/highcharts.d.ts. from the latest version today.
let result: Options = { /* some content in here, not relevant */};
let categories: Set<string> = new Set<string>();
....
if (result.xAxis === undefined)
result.xAxis = <AxisOptions> {};
result.xAxis.categories = Array.from(categories);
When I run this code through the tsc compiler I get the following error:
graph.ts(56,22): error TS2339: Property 'categories' does not exist on type 'AxisOptions | AxisOptions[]'.
However, when I check the source code, I see the following interface definition:
interface AxisOptions {
...
/**
* If categories are present for the xAxis, names are used instead of numbers for that axis. Since Highcharts 3.0,
* categories can also be extracted by giving each point a name and setting axis type to category. However, if you
* have multiple series, best practice remains defining the categories array.
* Example:
* categories: ['Apples', 'Bananas', 'Oranges']
* @default null
*/
categories?: string[];
.....
Any ideas what I'm doing wrong?
Many thanks!
please send a pull request. I'll review it.
Hi the problem is not the pull request, the problem is, that I don't see an error in the code.
The Typescript definition looks all good to me, for some reason its just not accepting it.
As you can see, I'm passing an array of strings to the categories field. The xAxis object is successfully recognized as an AxisOption. That's why this behavior is a little weird.
Anyone able to give some input on this?
Thanks!
Hi @vvakame, I was wondering, if there is any update on that?
Hello @sebastianzillessen,
The problem is that while categories exists on type AxisOptions (as you verified), it does not exist on type AxisOptions[], which is just an array. Therefore categories does not exist on type AxisOptions | AxisOptions[], which could be any of the two piped types.
If you are 100% certain that result.xAxis is indeed an AxisOptions and not an AxisOptions[] at the time when you call it, then you should be able to fix your issue with something like this:
(<AxisOptions>(result.xAxis)).categories = Array.from(categories);
Most helpful comment
Hello @sebastianzillessen,
The problem is that while
categoriesexists on typeAxisOptions(as you verified), it does not exist on typeAxisOptions[], which is just an array. Thereforecategoriesdoes not exist on typeAxisOptions | AxisOptions[], which could be any of the two piped types.If you are 100% certain that
result.xAxisis indeed anAxisOptionsand not anAxisOptions[]at the time when you call it, then you should be able to fix your issue with something like this:(<AxisOptions>(result.xAxis)).categories = Array.from(categories);