Coder Social home page Coder Social logo

Comments (5)

shakiba avatar shakiba commented on May 22, 2024

I just released v0.2.1 which includes TS definitions in npm package.

from planck.js.

badboy-tian avatar badboy-tian commented on May 22, 2024

you menu the index.d.ts? it can not work when use the Joint

from planck.js.

shakiba avatar shakiba commented on May 22, 2024

Can you please provide more details? How you are using it and what the issue is?

from planck.js.

Reta232 avatar Reta232 commented on May 22, 2024

I think the issue is with how the 'module' is defined:

From my experience in Typescript, modules get imported as such:

import { MyClass, myFunction, MY_CONST } from 'my-module';

however, the way the types are defined don't currently facilitate this due to it using a namespace. This leads to the following pattern:

import * as planck from './node_modules/planck-js';
const { Vec2 } = planck;

Another thing to note about this is that while it works, some module tools (i.e. vscode) won't pick up the module and import it in this manner.

A solution is to remove the namespace block and declare the module, exporting all of the necessities underneath (example):

import './index.js';

declare module 'planck-js';

export type BroadPhase = any;
// other exports...
declare namespace Manifold {
	export type Type = any;
}
// other exports...
export interface Vec2 {
	x: number;
	y: number;

	toString(): string;
	clone(): Vec2;
	setZero(): Vec2;
	set(x: number, y: number): Vec2;
	set(value: Vec2): Vec2;
	setCombine(a: number, v: Vec2, b: number, w: Vec2): Vec2;
	setMul(a: number, v: Vec2): Vec2;
	add(w: Vec2): Vec2;
	addCombine(a: number, v: Vec2, b: number, w: Vec2): Vec2;
	addMul(a: number, v: Vec2): Vec2;
	sub(w: Vec2): Vec2;
	subCombine(a: number, v: Vec2, b: number, w: Vec2): Vec2;
	subMul(a: number, v: Vec2): Vec2;
	mul(m: number): Vec2;
	length(): number;
	lengthSquared(): number;
	normalize(): number;
	neg(): Vec2;
	clamp(max: number): Vec2;
}
// other exports...
// Static Exports:

declare let Transform: {
	new (position: Vec2, rotation: number): Transform;
	(position: Vec2, rotation: number): Transform;

	new (): Transform;
	(): Transform;

	clone(xf: Transform): Transform;
	// neo(position: Vec2, rotation: number): Transform; internal
	identity(): Transform;
	isValid(o: any): boolean;
	assert(o: any): void;
	mul(a: Transform, b: Vec2): Vec2;
	mul(a: Transform, b: Transform): Transform;
	mul(a: Transform, b: Vec2[]): Vec2[];
	mul(a: Transform, b: Transform[]): Transform[];
	mulT(a: Transform, b: Vec2): Vec2;
	mulT(a: Transform, b: Transform): Transform;
};

Note, this might be alleviated if the code for pull request #66 follows this pattern.

from planck.js.

zOadT avatar zOadT commented on May 22, 2024

@Reta232 import "planck-js" is the current "intended" way of using the typings.
This is because initially the definitions were designed for @types. (Files in @types gets automatically loaded, so this would just add planck to global scope.)
I have to admit that I didn't reconsided this, so maybe we can adjust this.

from planck.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.