-
Notifications
You must be signed in to change notification settings - Fork 179
Open
Description
Reproducing steps
Consider the following
const input = {
_declaration: { _attributes: { version: '1.0', encoding: 'utf-8' } },
_comment: [
'Hello1',
'Hello2'
],
data: {some: 'value'}
}
const output= convert.js2xml(xmlData, { compact: true, spaces: 2 })
This code works as a JS module.
This is also explicitly tested in https://github.com/nashwaan/xml-js/blob/f0376f265c4f299100fb4766828ebf066a0edeec/test/test-items.js#L42C30-L42C30
Expected Outcome
This code should also work as a Typescript block as well.
Actual Outcome
TS compiler says _comment
does not accept string[]
TS2345: Argument of type '{ _declaration: { _attributes: { version: string; encoding: string; }; }; _comment: string[]; data: { some: string; }; }' is not assignable to parameter of type 'Element | ElementCompact'.
Type '{ _declaration: { _attributes: { version: string; encoding: string; }; }; _comment: string[]; data: { some: string; }; }' is not assignable to type 'ElementCompact'.
Types of property '_comment' are incompatible.
Type 'string[]' is not assignable to type 'string'.
Because,
Line 22 in f0376f2
_comment?: string |
_comment
as string only.
Proposed solution
can we make the type definition this intead?
_comment?: string | string[]
Metadata
Metadata
Assignees
Labels
No labels