I have been trying to use p5.js with TypeScript, but the definition seems incomplete. For example, the canvas property on the p5 class's instance member is private/not defined, despite existing as HTMLCanvasElement in reality.
import p5 from 'p5'
// Property 'canvas' does not exist on type...
const sketch = new p5(_ => console.log(sketch.canvas))
Since I haven't augmented a module before, I am having difficulty merging my own definitions with the library’s. I wrote something like this in my custom .d.ts file:
declare module 'p5' {
interface p5 {
canvas: HTMLCanvasElement
}
export default p5
export = p5
}
Now sketch.canvas is defined, but p5 itself becomes undefined (Type 'typeof p5' has no construct signatures.). My goal is to merge my definition with the library’s and not to overwrite everything. I don’t quite understand what I am doing wrong.