Ich glaube nicht, dass dies möglich ist, aber da dies:Zugriff auf eine Taste auf einem Typoskript Schnittstelle
Schnittstelle
import {BrowserService} from "../services/browser/index";
export interface IPrimaryNavigation {
opts:IPrimaryNavigationOpts;
}
export interface IPrimaryNavigationOpts {
...
browserService:BrowserService;
...
}
Klasse:
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.
}
}
Wie Sie umgehen dieses Problem. Ich kann keine Online-Beispiele finden, die sich mit einem solchen Problem befassen. Ich gebe zu, ich bin sehr neu in all dem.
Eigentlich ist das die richtige Antwort. Als ich @ AlexGs Ansatz der Verwendung von typeof versuchte, beklagte sich Typescript immer noch, dass es die "IPrimaryNavigationOpts" -Schnittstelle nicht finden konnte – Simon