Skip to content

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

@HimanshuGoel

Description

@HimanshuGoel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions