当前位置: 动力学知识库 > 问答 > 编程问答 >

inheritance - Use Interface with different namespaces in typescript

问题描述:

I want to create an interface in 'parent.a' namespace and I want to use that interface in 'parent' namespace.

Is there any way to do that, please help me on this.

I have found one solution to access classes from different namespaces access class from namespace but I need to work with interface not classes.

my example:

module Parent.AInterface {

export interface AInterface {

setParent(): void;

}

}

My other module

module Parent {

export class ParentClass implements AInterface {

}

}

while doing so.. I'm getting an error that says Cannot find name 'AInterface'

please help me on this.

网友答案:

You should mention module name before interface name:

module Parent.AInterface {    

    export interface AInterface {
        setParent(): void;
    }

} 


module Parent {

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

}

This works fine for me in the typescript playground.

网友答案:

Parent.ts

///<reference path="./Parent.AInterface.ts" />
module Parent {
     export class ParentClass implements AInterface.AInterface {}
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: