繁体   English   中英

在typescript中使用具有不同命名空间的接口

[英]Use Interface with different namespaces in typescript

我想在'parent.a'命名空间中创建一个接口,我想在'parent'命名空间中使用该接口。

有没有办法做到这一点,请帮助我。

我找到了一个解决方案来访问来自命名空间的不同命名空间访问类的类,但我需要使用接口而不是类。

我的例子:

module Parent.AInterface {    

    export interface AInterface {
        setParent(): void;
    }

} 

我的另一个模块

module Parent {

    export class ParentClass implements AInterface {

    }

}

这样做..我收到一个错误,上面写着找不到名字'AInterface'

请帮帮我。

你应该在接口名称之前提到模块名称:

module Parent.AInterface {    

    export interface AInterface {
        setParent(): void;
    }

} 


module Parent {

    export class ParentClass implements AInterface.AInterface {
        setParent() {
        }
    }

}

这在打字稿操场上对我来说很好。

Parent.ts

///<reference path="./Parent.AInterface.ts" />
module Parent {
     export class ParentClass implements AInterface.AInterface {}
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM