Comments (6)
I've just been looking into integrating TypeScript with canvas-sketch in a React project of mine. I've created a Wrapper component and have documented the types myself for now based on the documentation: https://gist.github.com/neefrehman/eb94d76e3bfd7e562d9f01fbebb97e19
Having access to up-to-date typings for the library would be super useful, would there be a simple way to generate and publish them to @types/canvas-sketch
?
from canvas-sketch.
One workaround to getting TypeScript support is to just use @ts-check
and type annotation via comments. That lets you get type checking on any JavaScript file without having to add a build step.
from canvas-sketch.
@joshwcomeau the CLI tool can receive extra arguments to be passed to browserify canvas-sketch [file] [opts] -- [browserifyArgs]
.
So you could potentially use https://github.com/TypeStrong/tsify or even https://github.com/babel/babelify with @babel/preset-typescript
.
from canvas-sketch.
This works like a charm:
https://gist.github.com/mattdesl/1e9ab019534838e8c870ae06371be469
from canvas-sketch.
I'd be happy to export types for canvas-sketch and its utilities, although I'm not too familiar with the Typescript ecosystem. Happy to hear more about how this could be done, and/or review some PRs. Cheers!
from canvas-sketch.
@mattdesl I tried my hand at typing the basics (RendererObjects & SketchManager excluded): #103
Usage example:
const canvasSketch = require('canvas-sketch');
import { SketchFunction, SettingsObject } from 'canvas-sketch';
const settings: SettingsObject = {
duration: 5,
animate: true,
dimensions: [512, 512],
};
const sketch: SketchFunction = () => {
return ({ context, width, height }) => {
context.fillStyle = 'orange';
context.fillRect(0, 0, width, height);
};
};
canvasSketch(sketch, settings);
from canvas-sketch.
Related Issues (20)
- TS support for new canvas HOT 9
- Very Complex to specify a generated canvas to a class HOT 6
- Error with threejs OrbitControls and canvas-sketch --template=three
- Using a sketch on a website HOT 6
- Issue creating file sketch-01.js HOT 4
- Link to the three example in default template doesn't resolve HOT 4
- Error to install on macOS Monterrey
- issue opening sketch-01.js HOT 3
- Add canvas-sketch as canvas to website HOT 1
- Build files with CSS HOT 1
- Can't install FFMPEG Streaming HOT 1
- Placing two canvas elements on top of each other HOT 2
- Method for saving canvas HOT 4
- how to implement navigator.requestMIDIAccess(); HOT 2
- canvas-sketch mysketch.js HOT 3
- Live reloading not working properly
- Exporting multiple png HOT 1
- Problem installing HOT 2
- Duplicate canvases HOT 1
- Error: spawn EINVAL HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from canvas-sketch.