-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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: chartHelpers.getRelativePosition(new Event(''), new Chart())
doesn't pass
#11153
Comments
@LeeLenaleee It seems you've run the example on a mobile device, correct? |
Just ran into same issue in latest after upgrade from v3... Error: libs/charts/src/lib/components/line/line.component.ts:74:69 - error TS2345: Argument of type 'Chart<"line", (number | Point | null)[], unknown>' is not assignable to parameter of type 'Chart'. Had to cast my chart to any. |
I'm guessing the When the chart has data, the unknown is then inferred from the data type. |
Hello.
The problem comes from the imports.
you should use
to make things work correctly inside typescript.
This change must be done inside chart.js project |
@candelrg are you able to send a PR with that change? |
Hello and sorry for the late answer. |
Hello again. |
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
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
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
Expected behavior
When passing a
Chart
instance to the helper methodgetRelativePosition()
I expect the types to be correct. In v3 this worked.Current behavior
The types don't match and the following error will be shown:
Reproducible sample
https://codesandbox.io/s/typescript-playground-export-forked-ufm45w?file=/index.ts:435-491
Optional extra steps/info to reproduce
Open the sandbox, ignore the runtime error and just look at the TS compiler error.
Possible solution
No response
Context
No response
chart.js version
v4.2.1
Browser name and version
No response
Link to your project
No response
The text was updated successfully, but these errors were encountered: