[英]Typescript error TS2449: Class 'x' used before its declaration, and insure that 'X' is declared here
Such this question is asked before here and here but it can't help.这样的问题在here和here之前被问过,但它无济于事。 my case is different.我的情况不同。
I have one typescript file containing 40 DTO class converted from C# file, like:我有一个 typescript 文件,其中包含从 C# 文件转换而来的 40 个 DTO class,例如:
//model.ts
export class A extends B
{
//...
}
export class B
{
//...
}
export class C
{
//...
}
export class D extends C
{
//...
}
//more classes
}
When I try to compile the file using tsc I get an error:当我尝试使用 tsc 编译文件时,出现错误:
model.ts:3:24 - error TS2449: Class 'B' used before its declaration.
3 export class A extends B
~
model.ts:8:14
8 export class B
~
'B' is declared here.
If I Generated the c# class as interface, compilation success without error.如果我生成了 c# class 作为接口,编译成功,没有错误。 tsc say that class B is declared here, but can't use it. tsc 说 class B 在这里声明,但不能使用它。
Sure, editing the file and moving the B class before A class, I get no error.当然,编辑文件并将 B class 移动到 A class 之前,我没有收到任何错误。
I want to avoid the manual editing of the converted file.我想避免手动编辑转换后的文件。
My Question: Is there an option in tsc configuration or other way to avoid this error and the manual editing of the generated file?我的问题:在 tsc 配置或其他方式中是否有一个选项可以避免此错误和手动编辑生成的文件?
I find a good tool that reorder the classes based on the dependency, so parent (base class) is written before the child.我找到了一个很好的工具,可以根据依赖关系对类重新排序,因此父类(基类)写在子类之前。
It's csharp2ts by @Rafael Salguero Iturrios , and it's an extension to VScode.它是@Rafael Salguero Iturrios 的 csharp2ts ,它是 VScode 的扩展。
I converted the c# file and the error disappear我转换了 c# 文件,错误消失了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.