how do i specify a union return type in `registerCustomXPathFunction`, or an "any" type?
i'm trying to register a function where the return type is not known (i'm, pretty sure the valid types are boolean, number, string and Array but i'm not 100% sure)
registerCustomXPathFunction(
{ namespaceURI: 'foo', localName: 'bar' },
[],
'xs:???', // what do i put here?
() => getSomeUnknownValue(),
)
i tried xs:anySimpleType and xs:anyAtomicType but they didn't work:
Error: Values of the type "xs:anySimpleType" can not be adapted from JavaScript to equivalent XPath values.
is there a way i can specify a union type, or disable the type checking with just an "any" type instead?
Hey there,
item()* is your answer. This includes nodes, arrays, maps, etcetera. Would be cool to extend the typing system here to include even more types, but this is where we are right now.
Kind regards,
Martin
thanks! another question: is there any equivalent type for null or undefined in (fonto)xpath? currently get this error when the function returns null or undefined:
Error: The JavaScript value null should be an array if it is to be converted to item()*.
Hey,
If its item()*, its just an empty array. Anything with * is seen as
returning an array, which is converted into a sequence. An empty sequence
is analogous to null in usage, so an empty array works!
Kr,
Martin
On Wed, 1 May 2024, 10:07 DetachHead, @.***> wrote:
thanks! another question: is there any equivalent type for null or undefined in (fonto)xpath? currently get this error when the function returns null or undefined:
Error: The JavaScript value null should be an array if it is to be converted to item()*.
— Reply to this email directly, view it on GitHub https://github.com/FontoXML/fontoxpath/issues/636#issuecomment-2088129426, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGKEJHDM2HPVHMNIART5YLZACPF3AVCNFSM6AAAAABG2DWLFGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBYGEZDSNBSGY . You are receiving this because you commented.Message ID: @.***>
awesome, thanks!