After installing canvas-sketch globally, create a new folder to hold your sketch:
mkdir my-sketch
cd my-sketchNow run the following to generate a new default .ts file, package.json, etc:
canvas-sketch sketch.ts --newOnce the server is running, kill it (Ctrl + C) and run the following to grab TypeScript, plugin and Node.js definitions:
npm install typescript tsify @types/node --save-devNow, overwrite the default file with the full sketch.ts code in this gist. If you copy the code to clipboard you can run the following:
pbpaste > sketch.tsNow you can run canvas-sketch again, but make sure to specify the tsify plugin like so, after a 'full stop' flag (--) which will pass down any additional browserify transforms/plugins.
canvas-sketch sketch.ts --open -- -p [ tsify --noImplicitAny ]Congrats! Now you are using TypeScript with canvas-sketch.
For anyone who is still coming here, my advice is to use typescript through JSDoc:
typescriptand@types/nodeas a dev dependency (example:npm install -D typescript @types/node)tsconfig.jsonusingnpx tsc --initand adding"checkJs": trueand"allowJs": trueto the"compilerOptions"canvas-sketch sketch.js --open)No need to download extra libs that will through weird errors which could lead to you overriding node_modules files 🙂
And the code example file in this gist will be
sketch.js