question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Property 'type' does not exist on type 'ChartConfigurationCustomTypesPerDataset'

See original GitHub issue

Expected behavior

It should not give a typescript error while accessing the ‘type’ property on the chart instance.

“Property ‘type’ does not exist on type ‘ChartConfigurationCustomTypesPerDataset’”

Current behavior

After migrating the ‘chart.js’ library from 3.7.1 to 3.9.1, the typescript compiler throws an error while accessing the ‘type’ property on the chart instance config object.

I have noticed that in this recent version a change has been introduced for the interface of chart instance type, but there is no ‘type’ attribute has been exposed on it -


export interface ChartConfigurationCustomTypesPerDataset<
  TType extends ChartType = ChartType,
  TData = DefaultDataPoint<TType>,
  TLabel = unknown
> {
  data: ChartDataCustomTypesPerDataset<TType, TData, TLabel>;
  options?: ChartOptions<TType>;
  plugins?: Plugin<TType>[];
}

After drilling down further into it, I noticed that in the 4.0.0-alpha.3 release, this property has been introduced on this interface against commit number. When I upgrade the library to this version, this issue went away. -

interface ChartConfigurationCustomTypesPerDataset<
  TType extends ChartType = ChartType,
  TData = DefaultDataPoint<TType>,
  TLabel = unknown
> {
  type: TType;
  data: ChartDataCustomTypesPerDataset<TType, TData, TLabel>;
  options?: ChartOptions<TType>;
  plugins?: Plugin<TType>[];
}

The problem is, this version is currently in alpha release so we can’t use it now, and no 3.9.x version contains this fix.

Reproducible sample

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgYQBYENZwL5wGZQQhwDkAxhrAHQBWAziQNwCwAUGwG6ZxkwAecALxwAJhDIBXEAFMAdjCoBzaTACiAG2kz5AIQCeASREAKAEQg9aTDFMBKOOjpwAEgBUAsgBlk6WVzoaWnIwLKxcUHAWVljCstIA7iiUMMa8fAA0iGxwOXAwemDSAFyk6sBxJOnZuSLoMOglCNW5ueroAEbS6nQlANqmAErSIqaZpjrqEtKjcKYAml3qEPEzpgDiUNJyqwAKElBgmqsA8lC+yqYAulWsLS219XQqPXC9Tbd3n22d6iUkAMRwCB4OAANQgMGkDBun0+DwarwAjAAmTKIgCcmQAzJkAKyZVFwLHXZp3bCXUnYGG5CBgGDACCyF7vT50MjoTTM0ktPiNbl3fk5KmCuB6PkfWFwEXYfkyiU4NjYWyhNhkRl0CCaKhLRTGKLJKhq2R4YCKKj5Qq2NhAA

Optional extra steps/info to reproduce

It can directly be seen in the typescript playground example -

image

Possible solution

The solution already has been introduced in the 4.0.0-alpha.3 but needs to backport for the 3.9.x version.

Context

No response

chart.js version

v3.9.1

Browser name and version

No response

Link to your project

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
LeeLenaleeecommented, Nov 11, 2022

Don’t have access to my PC till Sunday so you will need to wait till then

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chart.js Types of property 'type' are incompatible. ...
Looks like your TypeScript compiler is complaining because the chart type property is a specific type rather than a string. Option 1:.
Read more >
Chart.js - v4.1.1
Type parameters. Name, Type. TType, extends ChartType. # Type declaration ... ChartConfiguration | ChartConfigurationCustomTypesPerDataset & { type?
Read more >
[Solved]-Chart.js Types of property 'type' are incompatible. ...
Coding example for the question Chart.js Types of property 'type' are incompatible. Type 'string' is not assignable to type '"line" | "bar" ...
Read more >
Angular Charts Demo
There are one directive for all chart types: baseChart , and there are 8 types of ... Use this property or datasets /...
Read more >
Type 'Chart' is missing the following properties from type 'any[]'
This means if a function has a HandleScope and wants to return a handle/local it will not be available after the function returns....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found