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.

planck.js Typescript definitions lead to many errors with standard examples

See original GitHub issue

Hi all, I just set up the plank.js testbed with the 8-balls example from https://piqnt.com/planck.js/8-Ball - however, I used parcel as bundler and typescript. So I’m having the following in my index.ts:

import { planck as p } from 'planck-js/dist/planck-with-testbed.commonjs'
import * as pl from 'planck-js'

// From https://piqnt.com/planck.js/8-Ball:
p.testbed('8 Ball', function(testbed) {
    var Vec2 = pl.Vec2, Math = pl.Math;
  
    var SPI4 = Math.sin(Math.PI / 4), SPI3 = Math.sin(Math.PI / 3);
  
    var COLORED = true;
    var BLACK = {fill: 'black', stroke: 'white'};
...

This way the example runs fine, but I noticed many typescript errors. I found the following causes:

  1. The Shape constructor functions and classes bear the same name, e.g.
...
export function CircleShape(radius?: number): CircleShape;
export class CircleShape extends Shape {
  static TYPE: 'circle';
...

Somehow the typescript type checker is confused by this (as I am 😃) and at least in one click odyssee Visual Studio code windows crashed, I guess due to a cyclic relationship.

  1. Most interfaces declare their props in a mandatory way, such that the typescript type checker doesn’t allow partial objects, e.g. due to
export interface FixtureOpt {
  userData: any;
  friction: number;
  restitution: number;
  density: number;
...

any object not having e.g. an explicitly defined restitution will lead to a compiler error.

  1. Most of the @experiential functions (like Vec2.scaleFn) are not included in the Typescript types

=> Were this conscious “typescript type design decisions” or am I just the first one running into this? => Would anyone vote against adjusting the typescript files to resolve these issues? (if I feel like making a PR?)

Thanks!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
shakibacommented, Jan 9, 2021

Ah, I see, would you be able to see if moving stage-js from devDependencies to dependencies (in package.json) fixes importing issue?

@zOadT any idea about Math?

1reaction
zOadTcommented, Jan 7, 2021

Thanks for your comments!

  1. As far as I know this is supported in Typescript, but it requires a relatively new version. We have to check that
  2. Maybe the typings in the package on npm are outdated? In the repo they are optional (but I have only checked FixtureOpt and BodyDef)
  3. Yeah I think they were purposely not included, but I thinks its actually ok to include them. So feel free to add them
Read more comments on GitHub >

github_iconTop Results From Across the Web

planck.js Typescript definitions lead to many errors with standard ...
Hi all, I just set up the plank.js testbed with the 8-balls example from https://piqnt.com/planck.js/8-Ball - however, I used parcel as bundler and ......
Read more >
planck - npm
Planck.js is JavaScript (TypeScript) rewrite of Box2D physics engine for cross-platform HTML5 game development.
Read more >
JavaScript rewrite of 20k lines of Box2D C++ physics engine
I have ported/rewritten Box2D physics engine to JavaScript, for cross-platform HTML5 game development. Planck.js includes entire Box2D ...
Read more >
Surviving the TypeScript Ecosystem — Part 4 - Medium
TypeScript says there is a type error, that this property is missing, but I see the interface right here. It's fine.
Read more >
What is Planck's constant and why is it important? - TechTarget
Although Planck developed an accurate formula for all values, his equation was not mathematically unique. To keep it accurate, he had to define...
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