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
Types appear to be wrong for data #9688
Comments
Also noticed the type for the |
A solution for this would be to set the 2nd parametrized type for import { Chart, registerables, ChartConfiguration, ChartData } from 'chart.js';
const myData: (number | null)[] = [1,2,3,null];
const myDatasets ={ datasets: [{data: myData}], labels: ['1','2','3','4'] };
const getConfig = (): ChartConfiguration<'bar', (number|null)[]> => {
return {
type: 'bar',
data: myDatasets
}
} |
The pie animation type was fixed by #9699 |
The downside for allowing null in the types by default is: when accessing the data array, for example from a scriptable option, the value can be null. |
I put this into the 3.6.1 milestone. I think a solution here is to add some documentation on the types. I don't think we want to change the default type for the reasons @kurkle mentioned |
Expected Behavior
I expect to be able to type the data for a bar chart as
(number | null)[]
and have it not error.Current Behavior
I get the following error:
I think
null
is valid because of theskipNull
option, and it's useful for removing data in a stacked bar chart.Example
https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgYQBYENYBo5QKYDmwAzjHlOgEYA2exOamMyEAdgGbAECuFMwbBhlgARdDHRwAvnHZQIIOAHIAxsJgA6AFbElAbgBQBlW1JwQATzESAXHAAUrbiErk4AHzhPq1AJQBtAF04AF44fwBGLAAmLABmLG9qQMMTVjNLa3RiPBhiUKQAE3Fs3OI7fwRi23MrEqlAnGoqPGpy8KUIpSwlaO6lOP6AFiVgqUNjU3gCXJYOLlCHXztGWDnOHj4BVgAeJUpMJQA+UJOEAzhL3FzeVkQLq8fHmAswPDt9w6wHp6fq9DsmRKOTyPyeUjBEKAA
The text was updated successfully, but these errors were encountered: