Property 'type' does not exist on type 'ChartConfigurationCustomTypesPerDataset'
See original GitHub issueExpected 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
Optional extra steps/info to reproduce
It can directly be seen in the typescript playground example -
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:
- Created 10 months ago
- Comments:7
Top GitHub Comments
You need to cast it to the correct config type, will look into this later when I have more time if there is a way to detect which one got used so the correct typing is returned:
https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgYQBYENYBoUdsiAOwDNgBzAVynRmCLgF85ioIQ4ByAYzxgDoAVgGcOAbgCwAKCkA3THC4wAHnAC8cACYQuFEAFNC-MnpgBRADZ79hgEIBPAJIaAFACIQdtJhiuAlHHQhOAAJABUAWQAZZHRCOSELKwMYCUk5KDgPL1g1OEI9AHdcb2dFJRwEKThquBg7MD0ALk5zYHyOLCqajRp0ZsrJGqG4c3QAIz1zIWaAbVcAJT0NVxxXG3MKPRW4VwBNSfMIAu3XAHEoPQMTgAUqMEsTgHlqQmNXAF1OweHqnphAkzTOAzAY-H6jCbmZocADEcAgxDgADUIDA9CIvmDhn8+sCAIwAJhweIAnDgAMw4ACsOCJcHJny6PwY7yZjExNQgYFoRCBoOGQi46EsfLZQyU-TFwyl1QYHJ+dkl3yxMsYUoYbI1kgYvlSUi4vPgBpI5FyWV4fGNpDIASC2RgBBNlGoPMIqWNQngdQauSt5D43r0eskHoglj4hzIzkDuqkUiAA
Don’t have access to my PC till Sunday so you will need to wait till then