From 925bcb4c8d23271a28747ac5e0a1cb3de588c951 Mon Sep 17 00:00:00 2001 From: Sander Elias Date: Fri, 10 Jan 2020 08:45:36 +0100 Subject: [PATCH] fix(scully-routes.service): fix missing return type (#172) * fix(scully-routes.service): fix missing return type Put in the correct type for the return of the getCurrent function. In some cases TS inferrrence is off otherwise closes #171 * Adding extra types to this file. Co-authored-by: Aaron Frost --- .../lib/route-service/scully-routes.service.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/projects/scullyio/ng-lib/src/lib/route-service/scully-routes.service.ts b/projects/scullyio/ng-lib/src/lib/route-service/scully-routes.service.ts index 8fc0f7be1..21718282c 100644 --- a/projects/scullyio/ng-lib/src/lib/route-service/scully-routes.service.ts +++ b/projects/scullyio/ng-lib/src/lib/route-service/scully-routes.service.ts @@ -1,7 +1,8 @@ import {HttpClient} from '@angular/common/http'; import {Injectable} from '@angular/core'; -import {of, ReplaySubject} from 'rxjs'; +import {of, ReplaySubject, Observable} from 'rxjs'; import {catchError, shareReplay, switchMap, map, tap} from 'rxjs/operators'; +import {HandledRoute} from 'dist/scully'; export interface ScullyRoute { route: string; @@ -15,18 +16,16 @@ export interface ScullyRoute { }) export class ScullyRoutesService { private refresh = new ReplaySubject(1); - available$ = this.refresh.pipe( + available$: Observable = this.refresh.pipe( switchMap(() => this.http.get('/assets/scully-routes.json')), catchError(() => { - console.warn( - 'Scully routes file not found, are you running the in static version of your site?' - ); + console.warn('Scully routes file not found, are you running the in static version of your site?'); return of([] as ScullyRoute[]); }), shareReplay({refCount: false, bufferSize: 1}) ); - topLevel$ = this.available$.pipe( + topLevel$: Observable = this.available$.pipe( map(routes => routes.filter((r: ScullyRoute) => !r.route.slice(1).includes('/'))), shareReplay({refCount: false, bufferSize: 1}) ); @@ -36,10 +35,10 @@ export class ScullyRoutesService { this.reload(); } - getCurrent() { + getCurrent(): Observable { if (!location) { /** probably not in a browser, no current location available */ - return of([]); + return of(); } const curLocation = location.pathname; return this.available$.pipe( @@ -55,7 +54,7 @@ export class ScullyRoutesService { ); } - reload() { + reload(): void { this.refresh.next(); } }