3

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.

1
  • Are both modules declared in different files? If so, have you tried adding something like this ´///<reference path='pathToFile/first_file.ts'/>´ in the second class i.e. module Parent... ? Commented Apr 5, 2016 at 7:28

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Parent.ts

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.