fix: declare getMetaDataSymbol() as returning symbol | string
This commit is contained in:
1 parent
06226be0a8
commit
33b9effab3
3 files changed
+14
-2
No files matched your search
+1
-1
@@ -723,7 +723,7 @@ declare class XMLParser {
|
||||
* The XMLMetaData property is only present when {@link X2jOptions.captureMetaData}
|
||||
* is true in the options.
|
||||
*/
|
||||
static getMetaDataSymbol(): Symbol;
|
||||
static getMetaDataSymbol(): symbol | string;
|
||||
}
|
||||
|
||||
declare class XMLValidator {
|
||||
|
||||
@@ -41,6 +41,18 @@ const parsed = parser.parse(XML);
|
||||
|
||||
console.log(!!parsed);
|
||||
|
||||
// The metadata key indexes parsed nodes, so it has to be a primitive property key, not a boxed `Symbol`.
|
||||
const metaDataKey: PropertyKey = XMLParser.getMetaDataSymbol();
|
||||
const metaDataNode = new XMLParser({ captureMetaData: true }).parse(XML).SomeElement;
|
||||
|
||||
console.log(metaDataNode[metaDataKey], metaDataNode[XMLParser.getMetaDataSymbol()]);
|
||||
|
||||
// Without `Symbol` in the environment the key falls back to a plain property name.
|
||||
type StringKeyAccepted = string extends ReturnType<typeof XMLParser.getMetaDataSymbol> ? true : false;
|
||||
const stringKeyAccepted: StringKeyAccepted = true;
|
||||
|
||||
console.log(stringKeyAccepted);
|
||||
|
||||
const buildOpts: XmlBuilderOptions = {};
|
||||
|
||||
const builder = new XMLBuilder(buildOpts);
|
||||
|
||||
Vendored
+1
-1
@@ -724,7 +724,7 @@ export class XMLParser {
|
||||
* The XMLMetaData property is only present when {@link X2jOptions.captureMetaData}
|
||||
* is true in the options.
|
||||
*/
|
||||
static getMetaDataSymbol(): Symbol;
|
||||
static getMetaDataSymbol(): symbol | string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user