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.

Type Error with Shape and BoxShape in TypeScript

See original GitHub issue

So, I was getting started with some examples and creating a body with a fixture. The example HeavyOnLight has the code:

world.createDynamicBody(Vec2(0.0, 4.5)).createFixture(pl.Circle(0.5), 10.0);

since I am using TypeScript, my code is:

import pl from 'planck-js'
let world = new pl.World()
world.createBody().createFixture(pl.Box(100, 100))

TypeScript underlines the pl.Box part and says:

No overload matches this call.
  Overload 1 of 3, '(def: FixtureDef): Fixture', gave the following error.
    Argument of type 'BoxShape' is not assignable to parameter of type 'FixtureDef'.
      Type 'BoxShape' is missing the following properties from type 'FixtureDef': shape, userData, friction, restitution, and 5 more.
  Overload 2 of 3, '(shape: Shape, opt?: FixtureOpt | undefined): Fixture', gave the following error.
    Argument of type 'BoxShape' is not assignable to parameter of type 'Shape'.
      Type 'BoxShape' is missing the following properties from type 'Shape': m_type, m_radius, isValid, getRadius, and 7 more.
  Overload 3 of 3, '(shape: Shape, density?: number | undefined): Fixture', gave the following error.
    Argument of type 'BoxShape' is not assignable to parameter of type 'Shape'.

What am I doing wrong? It seems that BoxShape should be a child of Shape, but it isn’t? How can I add a fixture to a body?

EDIT: this happens with pl.Circle too, the error is Argument of type 'CircleShape' is not assignable to parameter of type 'Shape'.

I am using "planck-js": "^0.3.22" and "typescript": "^3.9.7"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
Doekecommented, Sep 26, 2020

I also encountered type errors with both Shapes and Fixture options object. I’m using the following workaround for now:

import { Shape } from 'planck-js/lib/shape/index'

const shape = Circle(Vec2(0, 0), 2) as unknown as Shape
this.fixture = this.body.createFixture(shape)
this.fixture.setSensor(true)
0reactions
zOadTcommented, Sep 27, 2020

PR #146 should fix this issue, it applies the suggestion of @Doeke. It would be great if you two could take a quick look at it. Unfortunately the same problems apply to the joint typings. I will fix these later in a separate PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Defining object shape variants in typescript - Stack Overflow
I am trying to define an object that can either contain data or an error. export type ...
Read more >
Shapes — python-pptx 0.6.21 documentation - Read the Docs
Shape -id collisions can occur (causing a repair error on load) if more than one Slide object is used to interact with the...
Read more >
Playground Example - Unknown in Catch - TypeScript
Unknown in Catch. Because JavaScript allows throwing any value, TypeScript does not support declaring the type of an error ...
Read more >
the argument type 'object - You.com | The search engine you control.
The argument type 'Object?' can't be assigned to the parameter type 'List'. The property 'length' can't be unconditionally accessed because the receiver can...
Read more >
@tldraw/core - npm
TypeScript icon, indicating that this package has built-in type declarations. 1.16.0 • Public • Published 2 days ago.
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