Testing Chart.js Instance Type Assignment and Validation in Chart.js
This test suite validates instance assignment and type checking in Chart.js TypeScript implementations. It focuses on verifying proper type enforcement for chart data structures and context interfaces, ensuring type safety when working with chart instances and datasets.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
chartjs/chartJs
test/types/test_instance_assignment.ts
import { Chart } from '../../src/types.js';
const chart = new Chart('id', {
type: 'scatter',
data: {
labels: [],
datasets: [{
data: [{ x: 0, y: 1 }],
pointRadius: (ctx) => ctx.parsed.x,
}]
},
});
interface Context {
chart: Chart;
}
const ctx: Context = {
chart: chart
};
// @ts-expect-error Type '{ x: number; y: number; }[]' is not assignable to type 'number[]'.
const dataArray: number[] = chart.data.datasets[0].data;