Chartjs-Class declaration merging for an existing type

0👍

The problem with module augmentation is always to find exactly what you want to augment. In this case you may think you want to augment the chart.js module but if we look at the definitions we see export as namespace Chart; This is an export for an UMD module and it is actually exporting a global class as a module (docs).

So the module is just referencing the global Chart class, this is what we really want to augment.

import * as Chart from 'chart.js';
type Tooltip = {t: any}

declare global {
    interface Chart {
        pluginTooltips?: Tooltip[];
    }
}

let c = new Chart(null!, null!);

c.pluginTooltips;  // ok now

Leave a comment