Skip to content

Types appear to be wrong for scriptable options #9670

@rhysviz

Description

@rhysviz

Expected Behavior

I am using a function as the value of backgroundColor on a bar chart. The allowed types should include a function that returns a color.

Current Behavior

The allowed types do not include a funciton:

Type '(context: any, options: any) => string' is not assignable to type 'string | _DeepPartialObject<CanvasGradient> | _DeepPartialObject<CanvasPattern> | undefined'.

Steps to Reproduce

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgYQBYENYBo5QKYDmwAzjHlOgEYA2exOamMyEAdgGbAECuFMwbBhlgARdDHRwAvnHZQIIOAHIAxsJgA6AFbElAbgBQRlW1JwCeZm04E4AXjgAKAJQAuFOpYcuvcQNYAPEqUmEoAfPYRCAZwsbiWvKyIMXGpMACeYHjuwaFYKamxEGD8pu7RhXEhKgDWBPLcrAAmLNTQ7iasZAAe8HZRBZVx+DCJygDE7FNKg6lS+UPSg1IGUkA

import { ChartConfiguration } from 'chart.js';

const getConfig = (): ChartConfiguration<'bar'> => {
    return {
        type: 'bar',
        options: {
        backgroundColor: context => {
            return '#fff'
        },
        }
    }
}

Environment

  • Chart.js version: 3.5.0
  • Typescript: 4.3.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions