planck.js Typescript definitions lead to many errors with standard examples
See original GitHub issueHi 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:
- 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.
- 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.
- 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:
- Created 3 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top GitHub Comments
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?
Thanks for your comments!