Touseef
Touseef

Reputation: 424

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.

Upvotes: 3

Views: 1325

Answers (2)

Kapil Kumar
Kapil Kumar

Reputation: 73

Parent.ts

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

Upvotes: 0

TSV
TSV

Reputation: 7641

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.

Upvotes: 1

Related Questions