xuri / xgen

XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator
BSD 3-Clause "New" or "Revised" License
318 stars 75 forks source link

TypeScript sequence `element`s are always `Array`s #15

Closed BatmanAoD closed 3 years ago

BatmanAoD commented 3 years ago

It appears that elements in a sequence are always treated as arrays by the TypeScript code generator. For instance, the existing base64.xsd test translates this XSD type:

  <complexType name="myType4">
    <sequence>
      <element name="title" type="string"/>
      <element name="blob" type="base64Binary"/>
      <element name="timestamp" type="dateTime"/>
    </sequence>
  </complexType>

...into this TypeScript type:

export class MyType4 {
    Title: Array<string>;
    Blob: Array<Array<any>>;
    Timestamp: Array<string>;
}

I believe the correct type would be:

export class MyType4 {
    Title: string;
    Blob: Array<any>;
    Timestamp: string;        // see issue #14
}