antvis/G6

Do you want to work on this issue?

You can request for a bounty in order to promote it!

[Bug]: type Element used in events is missing methods #6827

Crystal-RainSlide posted onGitHub

Describe the bug / é—®é¢˜ęčæ°

For example, methods in BaseNode like: drawKeyShape(), getIconStyle()​​, and getKeyStyle() don't exist on interface Node.


In this branch, I added:

type TargetElement = BaseNode | BaseEdge | BaseCombo;

Then I replaced references to Element with TargetElement.

https://github.com/Crystal-RainSlide/G6/tree/refactor-TargetElement

I can start a PR if you accept this solution. I'ill add the missing references if you find any.

No response

Steps to Reproduce the Bug or Issue / é‡ēŽ°ę­„éŖ¤

new G6.Graph({
  // other options...

  behaviors: [
    /** @type {import("@antv/g6").ClickSelectOptions} */
    ({
      type: "click-select",
      onClick: ({ target }) => {
        if ("getPorts" in target) { // Narrow target down from (Document | Element) to (Node | Combo)
          // TypeScript Error: target (Node | Combo) has no "drawKeyShape" method
          console.log(target.drawKeyShape);
          // Actually can log the method without type error
        }
      },
    }),
  ],

});

Version / ē‰ˆęœ¬

šŸ†• 5.x

OS / ę“ä½œē³»ē»Ÿ

  • macOS
  • Windows
  • Linux
  • Others / 其他

Browser / ęµč§ˆå™Ø

  • Chrome
  • Edge
  • Firefox
  • Safari (Limited support / ęœ‰é™ę”ÆęŒ)
  • IE (Nonsupport / äøę”ÆęŒ)
  • Others / 其他

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests