-
Notifications
You must be signed in to change notification settings - Fork 331
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
Type error with backgroundColor on options parameter for scriptable options #917
Comments
@thomas-haufe Thank you for feedback. The options passed by context need to be cast to the options related to the annotation type where the scriptable option is invoked. By default a annotation for The following code could solve the issue: import { Chart, ChartData, ChartOptions, Color } from 'chart.js';
import annotationPlugin, {BoxAnnotationOptions} from 'chartjs-plugin-annotation';
Chart.register(annotationPlugin)
const options: ChartOptions<'bubble'> = {
plugins: {
annotation: {
annotations: {
firstQuadrantBg: {
type: 'box',
backgroundColor: '#fff',
borderColor: (_, options) => {
const boxOptions = options as BoxAnnotationOptions;
return boxOptions.backgroundColor as Color;
},
}
}
}
}
} |
Thanks for the idea @stockiNail. Are you proposing it as a final solution or as a temporary workaround until this is fixed properly? I think this should be the job of the library and not the job of the consumer. And it's probably possible to let chartjs correctly infer the type with some advanced type gymnastics? :) |
@thomas-haufe currently the plugin is designed to cast the options when engaged in a scriptable options. |
Wouldn't it work to change the following line
to something like this? export type Scriptable<T, TContext, TYPE> = T | ((ctx: TContext, options: AnnotationOptions[TYPE]) => T); (or something similar)?
|
Error message:
Reproducible example:
https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgYQBYENYBoUdgEXRnRzUxgHkwZgIA7AZzgF84AzKCEOAcgGM8MAHQArBjwDcAWABQoSLDjo6dCMRr0ACgBsArgHNgddp279BYgLRg9hupeWr1tOpNmyysIVACmhhjA+UAAUjmpELjoGRgCU7jJ89AFwENQuDABcuORUGowAPDwARrpFRdo+PAB8cAC8iLJwcDbRjFkIjU1KKuF57Z1d3U4RSf0yg4NswFABAIq66AAmUMowAEL6YxMTMACeYD5ZxRAAHjxYA9twReh8ANb6nLp0i8gQ2tBHAMRsv+eX2yK0EWQTeHygWWCAH0cKk8gwYnUanD0kIbvdHhBnq93tALuMrswASxLkSCWSybIAG6YOB8GAnOpwRYQPi6EA+OjCfQ+GAAUQqHK5a12AElFsEAEQgXaeGCSxHoJgACQAKgBZAAyyGUNIYAp8Qpg0hkNKgcBlcqZdB8AHdsrBgvSTjgOgSmnsDkcSmUKv93cyiOgthNFkGGLzMnAANrEppuq5dbToIo+bRHMPECMwf2JpqZ4MxhAnLIARhwuyyACYcBC4ABmZiuktwGtwSsN2tZRsAXXxiabxL7pP7XRRoxSaSSo8HMhiEiAA
The text was updated successfully, but these errors were encountered: