Type Error with Shape and BoxShape in TypeScript
See original GitHub issueSo, 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:
- Created 3 years ago
- Reactions:1
- Comments:9 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I also encountered type errors with both Shapes and Fixture options object. I’m using the following workaround for now:
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.