Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript/Flow support #40

Closed
joshwcomeau opened this issue Nov 28, 2018 · 6 comments
Closed

Typescript/Flow support #40

joshwcomeau opened this issue Nov 28, 2018 · 6 comments

Comments

@joshwcomeau
Copy link

After having used this tool for a bit, I'm starting to really miss the type-safety I'm used to on other projects.

I definitely think the default should be vanilla JS, since it's much more familiar and lower-friction, but I wonder if it'd be worth setting it up to transpile Typescript or Flow? I think ideally, the user experience wouldn't change at all, except for it processing .ts files as well as .js.

(I've actually never used Typescript, I've used Flow extensively... but TS is much more popular than Flow, so it probably makes more sense to focus on that)

@aweary
Copy link

aweary commented Dec 18, 2018

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.

@dmnsgn
Copy link

dmnsgn commented Jan 16, 2019

@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.

@nkint
Copy link
Collaborator

nkint commented Oct 10, 2019

@nkint nkint closed this as completed Oct 10, 2019
@neefrehman
Copy link

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?

@mattdesl
Copy link
Owner

mattdesl commented Jul 2, 2020

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!

@henckellbach
Copy link

henckellbach commented Jul 6, 2020

@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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants