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

TypeScript error when using Chart.defaults.font.size = 8; in v 3.6.0 #9786

Closed
doberkofler opened this issue Oct 24, 2021 · 2 comments · Fixed by #9794
Closed

TypeScript error when using Chart.defaults.font.size = 8; in v 3.6.0 #9786

doberkofler opened this issue Oct 24, 2021 · 2 comments · Fixed by #9794
Labels
type: bug type: types Typescript type changes

Comments

@doberkofler
Copy link

Current Behavior

After upgrading from 3.5.1 to 3.6.0 the following statement reports a TypeScript error:

Chart.defaults.font.size = 8;
index.ts:181:22 - error TS2339: Property 'size' does not exist on type 'Scriptable<Partial<FontSpec>, ScriptableContext<keyof ChartTypeRegistry>>'.
  Property 'size' does not exist on type '(ctx: ScriptableContext<keyof ChartTypeRegistry>, options: AnyObject) => Partial<FontSpec> | undefined'.

181  Chart.defaults.font.size = 8;

Environment

  • Chart.js version: 3.6.0
@LeeLenaleee LeeLenaleee added the type: types Typescript type changes label Oct 24, 2021
@etimberg
Copy link
Member

I believe that this is related to #9680 which added partial<> around the FontSpec object. This typing is technically correct since these fields are not required.

You could use Chart.defaults.set('font', { size: 8 }) but you'll lose the type checking on the properties. @kurkle I'm not sure what the best option is here. My initial thought was to change the Defaults type to indicate what we ship as defaults but a user can change that at any time.

@JacoBriers
Copy link

JacoBriers commented Oct 29, 2021

This bit me recently when I tried to appease the type checker by doing:

Chart.defaults.font = {
  family: 'Roboto, "Helvetica Neue", Arial, sans-serif',
};

This broke things in weird and wonderful ways and took me a day to debug 😢 . Thanks for this fix!

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

Successfully merging a pull request may close this issue.

4 participants