fix: declare getMetaDataSymbol() as returning symbol | string

This commit is contained in:
dualfroz committed 2026-10-15 00:35:14 +02:00
1 parent 06226be0a8
commit 33b9effab3
3 files changed
+14 -2

No files matched your search

+1 -1
View File
@@ -723,7 +723,7 @@ declare class XMLParser {
* The XMLMetaData property is only present when {@link X2jOptions.captureMetaData} * The XMLMetaData property is only present when {@link X2jOptions.captureMetaData}
* is true in the options. * is true in the options.
*/ */
static getMetaDataSymbol(): Symbol; static getMetaDataSymbol(): symbol | string;
} }
declare class XMLValidator { declare class XMLValidator {
+12
View File
@@ -41,6 +41,18 @@ const parsed = parser.parse(XML);
console.log(!!parsed); 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 buildOpts: XmlBuilderOptions = {};
const builder = new XMLBuilder(buildOpts); const builder = new XMLBuilder(buildOpts);
+1 -1
View File
@@ -724,7 +724,7 @@ export class XMLParser {
* The XMLMetaData property is only present when {@link X2jOptions.captureMetaData} * The XMLMetaData property is only present when {@link X2jOptions.captureMetaData}
* is true in the options. * is true in the options.
*/ */
static getMetaDataSymbol(): Symbol; static getMetaDataSymbol(): symbol | string;
} }
/** /**