Automattic / node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
10.1k stars 1.16k forks source link

Context2d has no export #1865

Open Tolfx opened 3 years ago

Tolfx commented 3 years ago

Issue

Context2d is not being exported instead NodeCanvasRenderingContext2D is.. This causes an issue when I want to add more methods to Context2d by using the prototype.

But once compiled an error happens on runtime saying NodeCanvasRenderingContext2D is undefined.

Steps to Reproduce

import { NodeCanvasRenderingContext2D } from "canvas"
NodeCanvasRenderingContext2D.prototype.test= "test"; // Compiles and complains in runtime

But when using:

import { Context2d } from "canvas"
Context2d.prototype.test = "test";

It runs without issues but compiler complains that Module '"canvas"' has no exported member 'Context2d'.

Your Environment

almeidx commented 2 years ago

The way to fix this issue was to use NodeCanvasRenderingContext2D on the module augmentation, and CanvasRenderingContext2D at runtime, as per https://github.com/Automattic/node-canvas/pull/1866#issuecomment-889656888.

However, that no longer works since https://github.com/Automattic/node-canvas/commit/4a891ef22c5bdf56f3284279d490f53a8f60f396

@zbjornson why was the commit reverted? And do you have any other workarounds?