Skip to content

Commit 925bcb4

Browse files
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 <hi@frosty.io>
1 parent c1e6bf4 commit 925bcb4

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

projects/scullyio/ng-lib/src/lib/route-service/scully-routes.service.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {HttpClient} from '@angular/common/http';
22
import {Injectable} from '@angular/core';
3-
import {of, ReplaySubject} from 'rxjs';
3+
import {of, ReplaySubject, Observable} from 'rxjs';
44
import {catchError, shareReplay, switchMap, map, tap} from 'rxjs/operators';
5+
import {HandledRoute} from 'dist/scully';
56

67
export interface ScullyRoute {
78
route: string;
@@ -15,18 +16,16 @@ export interface ScullyRoute {
1516
})
1617
export class ScullyRoutesService {
1718
private refresh = new ReplaySubject<void>(1);
18-
available$ = this.refresh.pipe(
19+
available$: Observable<ScullyRoute[]> = this.refresh.pipe(
1920
switchMap(() => this.http.get<ScullyRoute[]>('/assets/scully-routes.json')),
2021
catchError(() => {
21-
console.warn(
22-
'Scully routes file not found, are you running the in static version of your site?'
23-
);
22+
console.warn('Scully routes file not found, are you running the in static version of your site?');
2423
return of([] as ScullyRoute[]);
2524
}),
2625
shareReplay({refCount: false, bufferSize: 1})
2726
);
2827

29-
topLevel$ = this.available$.pipe(
28+
topLevel$: Observable<ScullyRoute[]> = this.available$.pipe(
3029
map(routes => routes.filter((r: ScullyRoute) => !r.route.slice(1).includes('/'))),
3130
shareReplay({refCount: false, bufferSize: 1})
3231
);
@@ -36,10 +35,10 @@ export class ScullyRoutesService {
3635
this.reload();
3736
}
3837

39-
getCurrent() {
38+
getCurrent(): Observable<ScullyRoute> {
4039
if (!location) {
4140
/** probably not in a browser, no current location available */
42-
return of([]);
41+
return of();
4342
}
4443
const curLocation = location.pathname;
4544
return this.available$.pipe(
@@ -55,7 +54,7 @@ export class ScullyRoutesService {
5554
);
5655
}
5756

58-
reload() {
57+
reload(): void {
5958
this.refresh.next();
6059
}
6160
}

0 commit comments

Comments
 (0)