Skip to content

fix: problem with ChartOptions type #11866

Closed
@artus9033

Description

@artus9033

Expected behavior

When using a let chartInstance: Chart<TType> where TType is a generic such that: TType extends ChartType, accessing chartInstance.config.options?.plugins should cause no problems.

Current behavior

When using a let chartInstance: Chart<TType> where TType is a generic such that: TType extends ChartType, it turns out that accessing chartInstance.config.options?.plugins causes the following error:

Property 'plugins' does not exist on type '_DeepPartialArray<unknown> | (CoreChartOptions<TType> & ElementChartOptions<TType> & PluginChartOptions<TType> & DatasetChartOptions<...> & ScaleChartOptions<...>) | (Function & ... 4 more ... & ScaleChartOptions<...>) | _DeepPartialObject<...>'.
  Property 'plugins' does not exist on type '_DeepPartialArray<unknown>'.(2339)

Reproducible sample

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYQBYENYBoUdgFQE8wBTOAXzgDMoIQ4ByAYzxgDoArAZwYG4BYAFBCAbpjhMYADzgBeOABMITAK4gSAO3YBzEjACiAGxLqtAIUIBJBQAoARCEJpMMOwEo46LnAAS+ALIAMsjoGmJcRiaaMAKCYlBwjs6wcnAaJADuuC42klI4CEJwxXAwxCQAXIwARirV1cYMWEUlCugw6FWFgiW9cIbo1SSGXFUA2nYASiQKdjh2ZoYqJHNwdgCaw4YQGat2AOJQJJp7AAoqUGDGewDyUKG6dgC6zT19xW0dXHqjcGPd73eAyGhiqDAAxHAIFQ4AA1CAwEg8V6AvqfTp-ACMACYcJiAJw4ADMOAArDhcXAiS8Wu9yE9aRQUSUIGAYMAIBpfgC+lwmOhjNzGb0pF1hX1xcVyMz3oQxW9UZKKOLyIzVYJyG5YkIqCoNJIORo4LoYKcltpgFybmzDVwADz4IikOAkKSIjQKbzJGBOkgAPlyrCq3odvr9bh5RxgFyNLBcbFZ7M5XAA-GwrioLVzYuqgA

Optional extra steps/info to reproduce

No response

Possible solution

Most likely, to the ChartOptions interface, some part of the code introduces a DeepPartial<unknown[]> or alike. This results in ChartOptions<ChartType> being a union containing _DeepPartialArray<unknown>, which in turn breaks everything.

The most primitive and functional solution is excluding it manually from the ChartOptions type by wrapping the DeepPartial<...> with Exclude<..., DeepPartial<unknown[]>>.

Context

No response

chart.js version

4.4.3

Browser name and version

No response

Link to your project

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: typesTypescript type changes

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions