question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple errors using demo source code in Typescript

See original GitHub issue

I copied this code from the gravity demo to add mouse control in my typescript program

    // add mouse control
    var mouse = Mouse.create(render.canvas),
        mouseConstraint = MouseConstraint.create(engine, {
            mouse: mouse,
            constraint: {
                stiffness: 0.2,
                render: {
                    visible: false
                }
            }
        });

    Composite.add(world, mouseConstraint);

    // keep the mouse in sync with rendering
    render.mouse = mouse;

and got the following 3 errors:

Type ‘{ stiffness: number; render: { visible: false; }; }’ is missing the following properties from type ‘Constraint’: bodyA, bodyB, id, label, and 5 more.

Argument of type ‘MouseConstraint’ is not assignable to parameter of type ‘Body | Composite | Constraint’. Type ‘MouseConstraint’ is missing the following properties from type ‘Body’: angle, angularSpeed, angularVelocity, area, and 30 more.

Property ‘mouse’ does not exist on type ‘Render’.

I don’t see any easy workaround to using this mouse functionality in typescript.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
liabrucommented, Aug 21, 2021

I don’t maintain the TypeScript bindings so I can’t help much (they’re a separate project) but if there’s any TypeScript users willing to help them out, I think they take contributions.

1reaction
CJohnDesigncommented, Aug 25, 2022

@CJohnDesign I suppose worth contacting the maintainers on that as it seems overly strict, but for now I guess you could use @ts-ignore around that line e.g. like here?

That worked! this is how my code ended up looking! thanks

      mouseConstraint = MouseConstraint.create(engine, {
        mouse: mouse,
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        constraint: {
          stiffness: 0.2,
          render: {
            visible: false,
          },
        },
      })```
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript errors and how to fix them
Common Errors​​ Below you find a list of common TypeScript errors along with the buggy code and its fixed version.
Read more >
Complete list of Typescript error codes and their fixes
Looking at the 1.6.2 sources of the compiler, tsc.js , tsserver.js , typescript.js and typescriptServices.js , a variable called ts.
Read more >
Documentation - Understanding Errors - TypeScript
Let's work through some examples to see how they work in practice. Here's an example that produces an error message longer than the...
Read more >
Improving TypeScript error handling with exhaustive type ...
Discover an improved method for handling errors in TypeScript that solves problems that arise from returning null and throwing try...catch.
Read more >
How to solve too many try catch in Typescript ? - GeeksforGeeks
Example -1: In this example, we will create multiple try/catch blocks in order to catch multiple errors from different functions which actually ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found