Circular dependency caused by importing typescript type

前端 未结 4 579
借酒劲吻你
借酒劲吻你 2020-12-20 23:40

I\'m modeling data in typescript sent from a server to my Angular app. An Opportunity has a forms property containing an array of Form[]

4条回答
  •  清酒与你
    2020-12-21 00:24

    You can declare a class declare class Opportunity {} in form.ts file, TypeScript will assume that class is an external class and will be available at runtime. And you can skip import in one of the class.

    The only pain here is, you have to declare methods that you will be using for example,

    declare class Opportunity {
         method1(): void;
         method2(): number;
    }
    

    This class will serve as simple declaration and will not require method body. And VS intellisense will work correctly.

提交回复
热议问题