Skip to content

Conversation

@joshkel
Copy link
Contributor

@joshkel joshkel commented Dec 17, 2020

This addresses several mistakes I found in the TypeScript type definitions in my project. See individual commits' commit messages for details.

Specific notes and questions:

  • I originally thought that using Rollup to bundle the .d.ts files wasn't necessary, but I found out that it helps make module augmentation work. I added comments to types/index.esm.d.ts to help explain this, but if there's a better way to communicate or a better place to document, please let me know.
  • I noticed that the animation callbacks' AnimationEvent interface is ambiguous with a DOM event of the same name. Should it be renamed to something like ChartAnimationEvent (similar to the existing ChartEvent)?
  • I wasn't sure if callbacks are intended to support taking this as the item being operated on: several of the existing TypeScript definitions allow it, and the existing implementation does it, but I got the impression from Chart.js 3.x change lists and migration documentation that the code is moving away from it, so maybe it's in the process of being deprecated? Therefore, I omitted a this parameter from the types I updated, but if it should be there, I'm happy to add it.

core.controller.js's implementation also passes the Chart instance as `this`. However, that isn't documented, and it's my impression that Chart.js is moving away from passing items as `this`, so I didn't declare it in the type definitions.
The previous definition resolved to `{}` (which can allow primitives) if it was given a function, so it was far too broad for any `Scriptable<>` properties.
Document the `fn` option, since it's in the type definitions.

Fix callback usage to match example code.
The onProgress and onComplete events were mistakenly declared as taking the standard DOM AnimationEvent.  (Should Chart.js's AnimationEvent be renamed to ChartAnimationEvent to avoid any possible ambiguity?)
@etimberg etimberg added the type: types Typescript type changes label Dec 17, 2020
@etimberg etimberg merged commit efbaf2c into chartjs:master Dec 18, 2020
@joshkel joshkel deleted the typescript-updates branch December 18, 2020 18:16
@joshkel joshkel mentioned this pull request Mar 25, 2021
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 this pull request may close these issues.

3 participants