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 helpers Chart type #12012

Merged
merged 1 commit into from
Jan 30, 2025
Merged

Conversation

joshkel
Copy link
Contributor

@joshkel joshkel commented Jan 29, 2025

helpers.dom.ts functions referenced the internal Chart JavaScript class rather than the published Chart<TType, TData, TLabel> TypeScript definition. This causes errors when outside code tries to call helper functions.

The two Chart interfaces are incompatible - the width, height, and currentDevicePixelRatio properties are declared as readonly in the TS declaration but are manipulated by helpers.dom.ts functions, and helpers.dom.ts functions need to be invoked both by internal Chart.js code (which uses the JS class) and by outside code (which uses the TS types). To address this, I'm importing the JS version as PrivateChart. There may be a better solution.

It's my understanding that the comment about "typedefs are auto-exported" is obsolete now that helpers.dom is a native TS file.

Fixes #11153

helpers.dom.ts functions referenced the internal `Chart` JavaScript class rather than the published `Chart<TType, TData, TLabel>` TypeScript definition. This causes errors when outside code tries to call helper functions.

The two `Chart` interfaces are incompatible - the `width`, `height`, and `currentDevicePixelRatio` properties are declared as readonly in the TS declaration but are manipulated by helpers.dom.ts functions, and helpers.dom.ts functions need to be invoked both by internal Chart.js code (which uses the JS class) and by outside code (which uses the TS types). To address this, I'm importing the JS version as `PrivateChart`. There may be a better solution.

It's my understanding that the comment about "typedefs are auto-exported" is obsolete now that helpers.dom is a native TS file.

Fixes chartjs#11153
@etimberg etimberg added type: bug type: types Typescript type changes labels Jan 29, 2025
@etimberg etimberg added this to the Version 4.4.8 milestone Jan 29, 2025
@LeeLenaleee LeeLenaleee merged commit 370f6c3 into chartjs:master Jan 30, 2025
7 checks passed
@joshkel joshkel deleted the helper-type-fixes branch January 30, 2025 14:04
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 this pull request may close these issues.

TypeScript: chartHelpers.getRelativePosition(new Event(''), new Chart()) doesn't pass
4 participants