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

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

Open
10 tasks
Crystal-RainSlide opened this issue Mar 4, 2025 · 0 comments
Open
10 tasks

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

Crystal-RainSlide opened this issue Mar 4, 2025 · 0 comments
Labels
element Issue about elements

Comments

@Crystal-RainSlide
Copy link
Contributor

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.

Reproduction link / 复现链接

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 / 其他
@Crystal-RainSlide Crystal-RainSlide added the waiting for maintainer Triage or intervention needed from a maintainer. label Mar 4, 2025
@zhongyunWan zhongyunWan added element Issue about elements and removed waiting for maintainer Triage or intervention needed from a maintainer. labels Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
element Issue about elements
Projects
None yet
Development

No branches or pull requests

2 participants