Description
When creating an instance of XMLParser using the isArray option, the method arguments are currently defined as the following, with the jPathOrMatcher argument being either a string or Matcher type:
The behaviour as documented is that if the jPath option is set to true (or undefined since the default is true), then the type of jPathOrMatcher will be a string, and if jPath is false then the type of jPathOrMatcher will be a Matcher.
However, since the type of jPathOrMatcher is currently string | Matcher, to satisfy TypeScript I either have to add unnecessary conditional logic to check whether the type is string or Matcher, or add in a type assertion like (jPathOrMatcher as string).includes("blah").
I would like to propose updating the types so that it can smartly detect whether the jPath option is true or false, and set the type of isArray based on that. I've found that this can be achieved using union types, and I have a minimal working example using the TypeScript Playground:
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAsghsAxgCwgJygXigbwFBSFRpwB2AJgPYC2ACmpZGqAFxRkgDceAvt3qEhQAGgCYAVgHkwwAJaVSAZyy4CRWYoCCaEiAD8bABTA4AcwBycahDaLgaWaVMAaKONoJkt+45dQNmsA+AEYArsA2UMGUlAA2EGQAlFgAfFEx8WTcRG4ewMgGUPahENw8UAA+qjkBOnD6RiYWVpF2Dk6u1Ago6GzwSKhorgFBDmERbNFxCaTJmGlTmaTZRO6ebABmcLGKpbz8APQHUAAqqEXg0JQbRedr+exopqHWpMD+pP5adSBf7FBtXx4RAKOy5TwnNAlaRyUFsMRSGTyJQqfA1b66RpmSzWVz3ZDDLSjWTjCBzNJonJENAQYChNCfYp7HI8ZxqQj4thM3h4PBHU7nQRXG75aD4x7PV7vRxfbS6P5wAE+JzA0HvfEAVQoEA2jgg5BhyMU8IkhtBqPZsp+WOauPB+UJgRC4TJqWqVMINLpDKKUOZRB4PL5xzO0CFUGutzFeWQEpeEDeHyt8o0-36PTQqqU6pjADFtrszUoTYjYSjsJTCLVMVBjNiWp1uoNHcTSeT3R6vfTGX6VoRWZbOVAtjsILwgA
Would you like to work on this issue?
Bookmark this repository for further updates. Visit SoloThought to know about recent features.
Description
When creating an instance of
XMLParserusing theisArrayoption, the method arguments are currently defined as the following, with thejPathOrMatcherargument being either astringorMatchertype:The behaviour as documented is that if the
jPathoption is set totrue(orundefinedsince the default istrue), then the type ofjPathOrMatcherwill be astring, and ifjPathisfalsethen the type ofjPathOrMatcherwill be aMatcher.However, since the type of
jPathOrMatcheris currentlystring | Matcher, to satisfy TypeScript I either have to add unnecessary conditional logic to check whether the type isstringorMatcher, or add in a type assertion like(jPathOrMatcher as string).includes("blah").I would like to propose updating the types so that it can smartly detect whether the
jPathoption istrueorfalse, and set the type ofisArraybased on that. I've found that this can be achieved using union types, and I have a minimal working example using the TypeScript Playground:https://www.typescriptlang.org/play/?#code/C4TwDgpgBAsghsAxgCwgJygXigbwFBSFRpwB2AJgPYC2ACmpZGqAFxRkgDceAvt3qEhQAGgCYAVgHkwwAJaVSAZyy4CRWYoCCaEiAD8bABTA4AcwBycahDaLgaWaVMAaKONoJkt+45dQNmsA+AEYArsA2UMGUlAA2EGQAlFgAfFEx8WTcRG4ewMgGUPahENw8UAA+qjkBOnD6RiYWVpF2Dk6u1Ago6GzwSKhorgFBDmERbNFxCaTJmGlTmaTZRO6ebABmcLGKpbz8APQHUAAqqEXg0JQbRedr+exopqHWpMD+pP5adSBf7FBtXx4RAKOy5TwnNAlaRyUFsMRSGTyJQqfA1b66RpmSzWVz3ZDDLSjWTjCBzNJonJENAQYChNCfYp7HI8ZxqQj4thM3h4PBHU7nQRXG75aD4x7PV7vRxfbS6P5wAE+JzA0HvfEAVQoEA2jgg5BhyMU8IkhtBqPZsp+WOauPB+UJgRC4TJqWqVMINLpDKKUOZRB4PL5xzO0CFUGutzFeWQEpeEDeHyt8o0-36PTQqqU6pjADFtrszUoTYjYSjsJTCLVMVBjNiWp1uoNHcTSeT3R6vfTGX6VoRWZbOVAtjsILwgA
Would you like to work on this issue?
Bookmark this repository for further updates. Visit SoloThought to know about recent features.