我不认为这是可能的,但考虑到这一点:访问的关键
接口
import {BrowserService} from "../services/browser/index";
export interface IPrimaryNavigation {
opts:IPrimaryNavigationOpts;
}
export interface IPrimaryNavigationOpts {
...
browserService:BrowserService;
...
}
类:
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.
}
}
怎么办你解决了这个问题。我似乎无法在网上找到任何涉及此类问题的示例。我承认我对这一切都很新颖,所以赞赏。
其实,这是正确的答案。当我尝试@ AlexG使用typeof的方法时,Typescript仍然抱怨说它找不到'IPrimaryNavigationOpts'接口 – Simon