Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: problem with ChartOptions type #11866

Closed
artus9033 opened this issue Aug 16, 2024 · 0 comments · Fixed by #11867
Closed

fix: problem with ChartOptions type #11866

artus9033 opened this issue Aug 16, 2024 · 0 comments · Fixed by #11867
Labels
type: types Typescript type changes

Comments

@artus9033
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: types Typescript type changes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants