Skip to content

fixed xmlDoc type error #870

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Conversation

ygao9795
Copy link

@ygao9795 ygao9795 commented Apr 8, 2025

fixed this error:

src/urdf/UrdfModel.js:35:7 - error TS2322: Type 'Element | null' is not assignable to type 'Element | null | undefined'.
  Type 'Element' is missing the following properties from type 'Element': classList, className, clientHeight, clientLeft, and 102 more.

35       xmlDoc = parser.parseFromString(string, MIME_TYPE.XML_TEXT).documentElement;
         ~~~~~~


Found 1 error in src/urdf/UrdfModel.js:35

Add type assertion for xmldom Element compatibility

// Check if we are using a string or an XML element
    if (string) {
      // Parse the string
      var parser = new DOMParser();
      var parsedDoc = parser.parseFromString(string, MIME_TYPE.XML_TEXT);
      if (parsedDoc && parsedDoc.documentElement) {
        xmlDoc = parsedDoc.documentElement;
      } else {
        throw new Error('Failed to parse URDF string');
      }
    }
    if (!xmlDoc) {
      throw new Error('No URDF document parsed!');
    }

Copy link
Contributor

@MatthijsBurgh MatthijsBurgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests with correct and incorrect XML? To test it correctly raises and exception.

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

Successfully merging this pull request may close these issues.

2 participants