我不認爲這是可能的,但考慮到這一點:訪問的關鍵
接口
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