Gaweph / p5-typescript-starter

Base starter project using p5js and typescript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't access p5.dom methods

jbgh2 opened this issue · comments

When I try to reference any p5.dom methods, such as .parent(), I get the error:
sketch/sketch.ts(125,14): error TS2339: Property 'parent' does not exist on type 'Element'.

When I look in the p5.d.ts file I can see it's there.
Is there anything else I need to add?

Hello, it looks like createCanvas() returns the type HTMLCanvasElement which doesn't have a parent() method I'm afraid.

diag = p.createCanvas(canvas_width, canvas_height);
diag.parent('trappings-diag'); <-- will throw error

Here's what you are able to do with the HTMLCanvasElement:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement

Does this resolve your issue? (just looking at this quickly on my phone, if this answer is not helpful, will take a closer look tomorrow on the computer)

Not able to access any dom methods eg: createInput etc.

Not able to access any dom methods eg: createInput etc.

You will need to include the p5.dom library https://p5js.org/reference/#/libraries/p5.dom

This can be accomplished by adding this to your Head tag:
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/addons/p5.dom.min.js"></script>

In future updates I may add this be default to my example. Thanks for bringing to my attention.

@migom6 Dom and Sound libraries are now part of the default demo thanks for your input.