You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error TS2339: Property 'a' does not exist on type 'XMLSerializedAsObject | XMLSerializedAsObjectArray'.
Property 'a' does not exist on type 'XMLSerializedAsObjectArray'.
That’s because the return type of convert() is declared to be either an object or an array. But I think the actual returned value is always an object and never an array. For example, the following fails:
xmlbuilder2.convert(`<a>b</a><c>d</c>`,{format: "object"});// Error: The operation would yield an incorrect node tree. Document already has a document element node. Node is c.
As it stands, I still have to cast the return of convert() with as any.
Am I doing something wrong? Or could the declared return type of convert() be only XMLSerializedAsObject?
After thinking some more about it, the truth is that even if convert() returned an object, every property of that object could be an object or an array, so the benefit is limited. It may better to leave it as it is. Either you’re safe and always check for arrays, or you use a type assertion like I mentioned (as any).
From: oozcitak/xmlbuilder-js#147 (comment)
The text was updated successfully, but these errors were encountered: