From 33b9effab3701c913b1a7a6fa526bd5d07eba56d Mon Sep 17 00:00:00 2001 From: DualFroz Date: Thu, 15 Oct 2026 00:35:14 +0200 Subject: [PATCH] fix: declare getMetaDataSymbol() as returning symbol | string --- lib/fxp.d.cts | 2 +- spec/typings/typings-test.ts | 12 ++++++++++++ src/fxp.d.ts | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/fxp.d.cts b/lib/fxp.d.cts index eabd37d..506ffae 100644 --- a/lib/fxp.d.cts +++ b/lib/fxp.d.cts @@ -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 { diff --git a/spec/typings/typings-test.ts b/spec/typings/typings-test.ts index 43175b2..7e3ac05 100644 --- a/spec/typings/typings-test.ts +++ b/spec/typings/typings-test.ts @@ -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 ? true : false; +const stringKeyAccepted: StringKeyAccepted = true; + +console.log(stringKeyAccepted); + const buildOpts: XmlBuilderOptions = {}; const builder = new XMLBuilder(buildOpts); diff --git a/src/fxp.d.ts b/src/fxp.d.ts index 5ba0938..b7f9614 100644 --- a/src/fxp.d.ts +++ b/src/fxp.d.ts @@ -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; } /**