Code Monkey home page Code Monkey logo

Comments (6)

neefrehman avatar neefrehman commented on July 17, 2024 1

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.

aweary avatar aweary commented on July 17, 2024

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.

dmnsgn avatar dmnsgn commented on July 17, 2024

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

nkint avatar nkint commented on July 17, 2024

This works like a charm:
https://gist.github.com/mattdesl/1e9ab019534838e8c870ae06371be469

from canvas-sketch.

mattdesl avatar mattdesl commented on July 17, 2024

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.

henckellbach avatar henckellbach commented on July 17, 2024

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.