andycochrane
Posts: 2
Joined: Tue Mar 07, 2023 2:29 pm

Typescript: Property 'fromNode' does not exist on type 'Point'

Hello reader.

First post so I hope I don't unintentionally violate any forum rules.

I'm using Highcharts with Typescript and React and I have annotated the options object using the Options type.

In the tooltip.pointFormatter function, "this" is of type "Point". When I console.log "this", I can see "fromNode" and "toNode" properties that contain a lot of useful information – in particular, I want to use "name" – but when I try to access these properties, I get a typescript error.

Code: Select all

Property 'fromNode' does not exist on type 'Point'

Property 'toNode' does not exist on type 'Point'

I've created a minimal demo of this: https://codesandbox.io/s/sankey-tooltip ... /index.tsx

In this example, the chart renders just fine, but in my codebase the typescript errors would prevent my build from completing.

Note that I have commented out my current workaround which is to extend the point type and type-cast "this" using the extended type, but this workaround feels like a brittle solution and I would prefer to avoid it.

My question comes in several parts:
  1. Are these types missing due to the types being incomplete or have they been intentionally left out?
  2. If they have been intentionally left out, could you provide a little context as to why they have been? e.g. These properties are intended to be used internally only and accessing these properties in this way should be avoided.
  3. Is there another (better) way I can get the name of the from and to nodes of the current point from inside the point formatter?
Using "pointFormat" isn't an option because I need to do my own formatting of the {point.weight} property.

Cheers,

Andy.
jakub.j
Posts: 1091
Joined: Tue Jan 24, 2023 11:14 am

Re: Typescript: Property 'fromNode' does not exist on type 'Point'

Welcome to our forum and thanks for contacting us with your question!

If you use TypeScript, some properties are not added to the library by default, so you need to extend them by creating your own type.
Point.fromNode and Point.toNode are not part of our official documentation. See: https://api.highcharts.com/class-refere ... arts.Point

In highcharts-angular wrapper FAQ you have the exact explanation of your problem:
https://github.com/highcharts/highchart ... n-type-yyy

I'm sending you a demo, how the interface can be extended in your case:
https://codesandbox.io/s/sankey-tooltip ... ked-b5vrc3

Let me know if you have any further questions!
Best regards
Jakub
andycochrane
Posts: 2
Joined: Tue Mar 07, 2023 2:29 pm

Re: Typescript: Property 'fromNode' does not exist on type 'Point'

Thanks for your reply, Jakub.

It would seem my guess as to the reason for it not being available was correct and my workaround was essentially the same as what is recommended.

Are you able to tell me about the safety of referencing these internal properties? Can I expect these to remain unchanged in minor version updates? It would be good to know I can update to newer minor versions without my charts breaking.

Cheers,

Andy
jakub.j
Posts: 1091
Joined: Tue Jan 24, 2023 11:14 am

Re: Typescript: Property 'fromNode' does not exist on type 'Point'

Hi Andy,

You're right, what I proposed is the same as yours, because it's the correct and recommended way to do it.
They aren't any plans to change them in the future for now, but I think even if they change, your code will still be okey with that and you want get any errors.

Best regards
Jakub

Return to “Highcharts Usage”