Coder Social home page Coder Social logo

turbowarp-types's Introduction

Type definitions for the Scratch VM and editor

Scratch doesn't provide type definitions for their libraries, so we wrote our own.

This repository only contains types for the vanilla (LLK) Scratch runtime and editor. For the additional types in the TurboWarp runtimes, see @turbowarp/types-tw.

Module Status
scratch-vm
scratch-render
scratch-svg-renderer
scratch-render-fonts
scratch-audio
scratch-storage
scratch-parser
scratch-blocks 🚧
scratch-gui redux
scratch-paint redux
scratch-www redux

Using from npm

First, install the types:

npm install @turbowarp/types

Next, you must use tsconfig.json to configure TypeScript to know how to find the types.

{
  "compilerOptions": {
    // If you use require() or "module": "CommonJS", remove these lines.
    // If you use "module": "ES6", synthetic default imports are required.
    "module": "ES6",
    "allowSyntheticDefaultImports": true,

    // Tell TypeScript where to find the types for Scratch libraries.
    "paths": {
      "scratch-vm": ["./node_modules/@turbowarp/types/index.d.ts"],
      "scratch-render": ["./node_modules/@turbowarp/types/index.d.ts"],
      "scratch-svg-renderer": ["./node_modules/@turbowarp/types/index.d.ts"],
      "scratch-render-fonts": ["./node_modules/@turbowarp/types/index.d.ts"],
      "scratch-storage": ["./node_modules/@turbowarp/types/index.d.ts"],
      "scratch-audio": ["./node_modules/@turbowarp/types/index.d.ts"],
      "scratch-parser": ["./node_modules/@turbowarp/types/index.d.ts"],
      "scratch-blocks": ["./node_modules/@turbowarp/types/index.d.ts"]
    },

    // Recommended strictness settings. Change as you please.
    "strictNullChecks": true,
    "noImplicitAny": true,
    "noImplicitThis": true
  }
}

Then in your JavaScript or TypeScript:

import VM from 'scratch-vm';
const vm = new VM();
vm.loadProject(/* read a project somehow */ new ArrayBuffer(100))
  .then(() => {
    vm.start();
    vm.greenFlag();
  });

Or if you still use require():

const VM = require('scratch-vm');
const vm = new VM();
vm.loadProject(/* read a project somehow */ new ArrayBuffer(100))
  .then(() => {
    vm.start();
    vm.greenFlag();
  });

Tests

There are some tests in the tests folder. These files are never actually run, but the code will be type checked.

License

Type definitions and test code are licensed under the Apache 2.0 license.

The libraries being documented may be under different licenses.

turbowarp-types's People

Contributors

garbomuffin avatar seheon99 avatar tacodiva avatar

Stargazers

 avatar

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.