for p5js v1 types, see branch v1
Generates TypeScript definitions for p5.js.
The generated typings are published to @types/p5.
To install the typings, run npm install --save @types/p5.
Then, look in the examples directory for inspiration.
p5.d.ts is for p5 used in instance mode and global.d.ts is for p5 in global mode.
global.d.ts references p5.d.ts, so you must include both if global mode is used.
To generate typings yourself, try out:
npm i
npm run allthe generated typings are put at p5 directory.
p5js has official playground https://editor.p5js.org/, but it misses the typing hint. Here is a solution.
See sketch.js as an exmaple. After generating the types.
/// @ts-check
/// <reference path="../../types/p5/global.d.ts" />
const p5 = require("../../types/p5");
// here comes the code.use VS Code and Live Server plugin to auto reload your graph when code changes.
the browser will complain in the console that
sketch.js:5 Uncaught ReferenceError: require is not defined
at sketch.js:5:12but it works.
- In p5.js v2, upstream use jsdoc to generate
.d.tsfiles, so now this package just pull the type file from npm and extract thetar.gz. So contribute to the p5.js