Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when using pointerdown on Sprite #99

Closed
dsoskey opened this issue Mar 7, 2019 · 3 comments
Closed

TypeError when using pointerdown on Sprite #99

dsoskey opened this issue Mar 7, 2019 · 3 comments

Comments

@dsoskey
Copy link

dsoskey commented Mar 7, 2019

Description

I'm trying to add typing to a class that uses react-pixi-fiber's Sprite and I get the following error:

Type error: Type '{ x: number; y: number; width: number; height: number; texture: Texture; anchor: any; rotation: number; pointerdown: (event: any) => void; interactive: true; buttonMode: true; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Sprite> & Readonly<PropsWithChildren<SpriteProperties>>'.
  Property 'pointerdown' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Sprite> & Readonly<PropsWithChildren<SpriteProperties>>'.  TS2322

    22 |
    23 |     return (
  > 24 |       <Sprite
       |        ^
    25 |         x={node.x} y={node.y}
    26 |         width={NODE_SIZE} height={NODE_SIZE}
    27 |         texture={PIXI.Texture.fromImage(node.track ? node.track.image_cover || DEFAULT_IMAGE_PATH : DEFAULT_IMAGE_PATH)}

Has anyone run into the same or a similar typing issue?

Relevant Code

class with offending error

export default class NodeSprite extends React.Component<NodeProps, NodeState> {
  onNodeClick = (event: any) => {
    // implementation
  }

  render() {
    const { node, currentNode } = this.props;

    return (
      <Sprite
        x={node.x} y={node.y}
        width={NODE_SIZE} height={NODE_SIZE}
        texture={PIXI.Texture.fromImage(node.track ? node.track.image_cover || DEFAULT_IMAGE_PATH : DEFAULT_IMAGE_PATH)}
        anchor={centerAnchor}
        pointerdown={this.onNodeClick}
        interactive
        buttonMode
      />
    );
  }
}

tsconfig.json


Additional info

  • react-pixi-fiber version: 0.7.0
  • React version: ^16.7.0
  • ReactDOM version: ^16.7.0
  • PixiJS version: ^4.8.6
@liajoy
Copy link
Contributor

liajoy commented Mar 21, 2019

I've been through this before.
Some codes of PIXI's declaration file need modify, so the declaration file should be copied to this library. Then add PIXI event's types into ReactPixiFiber's declaration file.
I don't know is there a need to make a pr for this. @michalochman

@michalochman
Copy link
Owner

@liajoy I don't use TypeScript so I'm not sure how to fix it, but I had a look at PIXI types and they have type InteractionEventTypes. Is it possible to use this?

@liajoy
Copy link
Contributor

liajoy commented Mar 21, 2019

@michalochman yes, these events is what we need to add to PIXI.displayObject class in PIXI types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants