0

I don't think this is possible, but given this:

interface

import {BrowserService} from "../services/browser/index";

export interface IPrimaryNavigation {
    opts:IPrimaryNavigationOpts;
}

export interface IPrimaryNavigationOpts {
    ...
    browserService:BrowserService;
    ...
}

class:

import {IPrimaryNavigation, IPrimaryNavigationOpts} from "./interface";

export class PrimaryNavigation implements IPrimaryNavigation {
   public opts:IPrimaryNavigationOpts;
   ...
   mounted():void {
        ...
        this.listenForBootstrap(this.opts.bsNav, this.opts.browserService);
    }
    listenForBootstrap(menuName:string,browserService:<???>):void {
                                                       ^^^ here is the problem - 
    // I want to do the equivalent of IPrimaryNavigationOpts.browserService but can't. 
    // I don't think I should have to import the IBrowserService explicitly.

    }
}

How do you get around this issue. I can't seem to find any examples online that deal with such an issue. I admit I am very new to all of this, so pointers appreciated.

2 Answers 2

1

We can re-export used stuff. So, inside of the "./interface" we can do (check the last lines):

import {BrowserService} from "../services/browser/index";

export interface IPrimaryNavigation {
    opts:IPrimaryNavigationOpts;
}

export interface IPrimaryNavigationOpts {
    ...
    browserService:BrowserService;
    ...
}
// re-export used interface
export { BrowserService }

And now, we can import even that type

// we import the re-exported type
import {IPrimaryNavigation, IPrimaryNavigationOpts
        BrowserService } from "./interface";

export class PrimaryNavigation implements IPrimaryNavigation {
   public opts:IPrimaryNavigationOpts;
   ...
   mounted():void {
        ...
        this.listenForBootstrap(this.opts.bsNav, this.opts.browserService);
    }
    listenForBootstrap(menuName:string,browserService:BrowserService):void {
    //listenForBootstrap(menuName:string,browserService:<???>):void {
    //                                                   ^^^ here is the problem - 
    // I want to do the equivalent of IPrimaryNavigationOpts.browserService but can't. 
    // I don't think I should have to import the IBrowserService explicitly.

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

1 Comment

Actually, this is the correct answer. When I tried @AlexG's approach of using typeof, Typescript still complained that it could not find IPrimaryNavigationOpts interface
0

You can type it as: browserService: typeof IPrimaryNavigationOpts.browserService

1 Comment

Error TS2304: Cannot find name 'IPrimaryNavigationOpts'. This quite weird.

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.