简体   繁体   English

Typescript 错误 TS2449: Class 'x' 在其声明之前使用,并确保在此处声明 'X'

[英]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.这样的问题在herehere之前被问过,但它无济于事。 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.

相关问题 TypeScript 错误 TS2449: Class 'x' 在其声明之前使用 - TypeScript error TS2449: Class 'x' used before its declaration 在声明之前使用的“X”类 - Class 'X' used before its declaration 尝试使用自定义钩子会给出错误“在声明之前使用块范围变量'X'”。 - Trying to use custom hook gives error “Block-scoped variable 'X' used before its declaration.” 解构块作用域变量时出现 TS 错误,不能在其声明之前使用 - TS error when descturturing Block scoped variable cannot be used before its declaration 声明前使用的“ Bar”类 - Class 'Bar' used before its declaration TS - 在分配之前使用变量“x”。 TS(2454) - TS - Variable 'x' is used before being assigned. TS(2454) 尝试覆盖 function 中的变量并出现错误:“块作用域变量‘...’在其声明之前使用。ts(2448)” - Trying to override a variable inside a function and get an error: "Block-scoped variable '...' used before its declaration.ts(2448)" 在声明之前使用的块范围变量“向导”.ts(2448) - Block-scoped variable 'wizard' used before its declaration.ts(2448) 错误 TS2729:属性“扩展”在其初始化之前被使用 - error TS2729: Property 'expanded' is used before its initialization Typescript 错误 - “类型已声明但从未使用” in.ts。 在界面中使用时 - Typescript error - “type is declared but never used” in .ts. When it was used in interface
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM