无法使用cxml生成的TypeScript接口

无法使用cxml生成的TypeScript接口,typescript,xsd,xml-parsing,Typescript,Xsd,Xml Parsing,我正在使用TypeScript为XML REST服务实现API包装器。所有请求和响应都在模式中描述,我能够使用并生成适当的TypeScript和JS定义。但我对cxsd生成的代码感到困惑。例如,以下是简化版本: interface _foo { a: string; b: bar; } interface foo extends _foo { constructor: { new(): foo } } var foo: { new(): foo }; interface _ba

我正在使用TypeScript为XML REST服务实现API包装器。所有请求和响应都在模式中描述,我能够使用并生成适当的TypeScript和JS定义。但我对cxsd生成的代码感到困惑。例如,以下是简化版本:

interface _foo {
    a: string;
    b: bar;
}
interface foo extends _foo { constructor: { new(): foo } }
var foo: { new(): foo };

interface _bar { 
    c: string;
}
interface bar extends _bar { constructor: { new(): bar } }
var bar: { new(): bar };
构造函数:{new():foo}
到底意味着什么

我需要亲自创建这些对象来构建XML并将其发送到API后端,但我无法做到这一点。尝试类似于:

let obj: foo = {
    a: "Test1",
    b: {
        c: "Test2"
    }
}
我得到这个错误:

scripts/foo.ts (13,5): Type '{ a: string; b: { c: string; }; }' is not assignable to type 'foo'.
  Types of property 'constructor' are incompatible.
    Type 'Function' is not assignable to type 'new () => foo'.
      Type 'Function' provides no match for the signature 'new (): foo' (2322)

如何创建这些对象?在这里使用TypeScript的整个想法是验证它们与原始XSD模式100%兼容。

如果这是您想要的代码

let obj: Foo = {
    a: "Test1",
    b: {
        c: "Test2"
    }
}
这是您需要的类型定义

interface Foo {
  a: string,
  b: {
    c: string
  }
}
这里使用TypeScript的整个想法是验证它们与原始XSD模式100%兼容

你得自己写。或者找一个工具(我认为不存在满足您质量要求的工具,也就是有效的工具)