Skip to content

fix(entities): declare EntityDecoder as the named export it is, with setXmlVersion - #6

Merged
amitguptagwl merged 1 commit into
nodable:mainfrom
YevheniiKotyrlo:fix/entity-decoder-declaration
Sep 29, 2026
Merged

amitguptagwl merged 1 commit into
nodable:mainfrom
YevheniiKotyrlo:fix/entity-decoder-declaration

Conversation

@YevheniiKotyrlo

Copy link
Copy Markdown
Contributor

Problem

index.d.ts declares EntityDecoder as the default export, but index.js exports it by name:

// Entity/src/index.js
export { default as EntityDecoder, ENTITY_ACTION } from './EntityDecoder.js';
// Entity/src/index.d.ts
export default class EntityDecoder {

In TypeScript the import that runs does not compile, and the import that compiles does not run. This holds for every consumer, measured against the published 3.0.0 (latest), whose src/index.d.ts is the same blob as main (c513cf5):

Import tsc --strict --module nodenext Node
import { EntityDecoder } from '@nodable/entities' TS2724: … has no exported member named 'EntityDecoder'. Did you mean 'EntityEncoder'? works
import EntityDecoder from '@nodable/entities' compiles SyntaxError: The requested module … does not provide an export named 'default'

The class also omits setXmlVersion(version), which docs/EntityDecoder.md documents and fast-xml-parser calls once it reads <?xml version?>, so decoder.setXmlVersion(1.1) is TS2339.

#4 and #1 reported the export half and were closed with "Can you please confirm?". This is that confirmation: the declaration 3.0.0 ships is unchanged.

Solution

  • export class EntityDecoder, matching the named export index.js provides.
  • setXmlVersion(version: number): void, matching the runtime's @param {1.0|1.1|number} version and the Number(ver) || 1.0 fast-xml-parser passes.
  • The hooks example in docs/EntityDecoder.md used the default import; it now uses the named one, like every other example there.

Tests

The package has no type tests, so the evidence is a probe compiled against src/index.d.ts and run against src/index.js:

import { EntityDecoder } from '@nodable/entities';
const decoder = new EntityDecoder({ numericAllowed: true });
decoder.setXmlVersion(1.1);
console.log(JSON.stringify(decoder.decode('first&#10;second')));

Before: TS2724 on the import (and TS2339 on setXmlVersion with the default import). After: tsc exits 0 and Node prints "first\nsecond".

Verification

jest 3 suites, 246 passed · the probe above compiles and runs · declarations and docs only, no runtime change.

Searched the tracker for EntityDecoder, default export, setXmlVersion and index.d.ts: #1 and #4 are the only hits, both closed.

Base

Cut from d2070d7 (main), merges cleanly.

…setXmlVersion

index.js exports EntityDecoder by name (`export { default as EntityDecoder }`),
but index.d.ts declares it as the default export. The named import a consumer
needs therefore fails to type-check (TS2724), while the default import the
declaration advertises throws when the module links, because there is no
'default' export.

The declaration also omits setXmlVersion, which docs/EntityDecoder.md
documents and fast-xml-parser calls once it has read `<?xml version?>`.

The docs example that used the default import now uses the named one.
@amitguptagwl

Copy link
Copy Markdown
Contributor

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants