NaturalIntelligence / fast-xml-parser

Validate XML, Parse XML and Build XML rapidly without C/C++ based libraries and no callback.
https://naturalintelligence.github.io/fast-xml-parser/
MIT License
2.45k stars 296 forks source link

Change the typedefs and docs for updateTag to match how FXP actually behaves #579

Open ChrisMBarr opened 1 year ago

ChrisMBarr commented 1 year ago

Purpose / Goal

According to the comments in discussion #576 the updateTag method actually allows for the undefined return type. This PR makes two simple changes:

Type


Regarding the typedefs update

Currently returning undefined while using typescript will give this error

Type '(tagName: string, jPath: string, attrs: { [k: string]: string; }) => false | "A" | undefined' is not assignable to type '(tagName: string, jPath: string, attrs: { [k: string]: string; }) => string | boolean'.
  Type 'false | "A" | undefined' is not assignable to type 'string | boolean'.
    Type 'undefined' is not assignable to type 'string | boolean'.ts(2322)

The update the the typedefs will fix this and allow this to happen.

Regarding the docs update

A note about the example output in the docs that I added. This is the exact output when I tested it by running the code example given in the docs. It seems to say that"At": "Home" is added as an attribute on the A tag, but also "At": "Home" seems to be added as an element. This seems odd to me but I'm also somewhat new to FXP and I'm not sure if this is intended behavior or not. Regardless though, this is what the output is, and now the docs will give an example of that.

Regarding returning undefined

As far as I can tell when updateTag method has return undefined, it behaves exactly the same as return false. The docs and the typedefs now explicitly mention that.