Skip to content

Commit f314c63

Browse files
authored
feat!: make parameter selector types stricter (#278)
# Feature - Remove type parameter from `selectQueryParam` - Specify strict observable type returned from `selectQueryParam` - Remove type parameter from `selectRouteParam` - Specify strict observable type returned from `selectRouteParam` BREAKING CHANGE: - Stricter types for `selectQueryParam` Before: ```typescript // Actual emitted values are of type `string | undefined` regardless of what we specify const filter$ = routerStore.selectQueryParam<string | null>('filter'); ``` After: ```typescript // Emitted values are implicitly of type `string | undefined` and are only changeable through operators const filter$ = routerStore.selectQueryParam('filter').pipe( map(filter => filter ?? null), ); ``` - Stricter types for `selectRouteParam` Before: ```typescript // Actual emitted values are of type `string | undefined` regardless of what we specify const id$ = routerStore.selectRouteParam<number>('id'); ``` After: ```typescript // Emitted values are implicitly of type `string | undefined` and are only changeable through operators const id$ = routerStore.selectRouteParam('id').pipe( map(id => id === undefined ? undefined : Number(id), ); ```
1 parent c46e777 commit f314c63

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ Published with partial Ivy compilation.
1919

2020
A `RouterStore` service has the following public properties:
2121

22-
| API | Description |
23-
| ----------------------------------------------------------- | ------------------------------------------ |
24-
| currentRoute$: Observable<MinimalActivatedRouteSnapshot> | Select the current route. |
25-
| fragment$: Observable<string \| null> | Select the current route fragment. |
26-
| queryParams$: Observable<Params> | Select the current route query parameters. |
27-
| routeData$: Observable<Data> | Select the current route data. |
28-
| routeParams$: Observable<Params> | Select the current route parameters. |
29-
| url$: Observable<string> | Select the current URL. |
30-
| selectQueryParam<TValue>(param: string): Observable<TValue> | Select the specified query parameter. |
31-
| selectRouteParam<TValue>(param: string): Observable<TValue> | Select the specified route parameter. |
22+
| API | Description |
23+
| ---------------------------------------------------------------- | ------------------------------------------ |
24+
| currentRoute$: Observable<MinimalActivatedRouteSnapshot> | Select the current route. |
25+
| fragment$: Observable<string \| null> | Select the current route fragment. |
26+
| queryParams$: Observable<Params> | Select the current route query parameters. |
27+
| routeData$: Observable<Data> | Select the current route data. |
28+
| routeParams$: Observable<Params> | Select the current route parameters. |
29+
| url$: Observable<string> | Select the current URL. |
30+
| selectQueryParam(param: string): Observable<string \| undefined> | Select the specified query parameter. |
31+
| selectRouteParam(param: string): Observable<string \| undefined> | Select the specified route parameter. |
3232

3333
A `RouterStore` service is provided by using either `provideGlobalRouterStore` or `provideLocalRouterStore`.
3434

packages/router-component-store/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ngworker/router-component-store",
3-
"version": "0.1.2-alpha.8",
3+
"version": "0.2.0-alpha.0",
44
"description": "An Angular Router-connecting NgRx component store.",
55
"license": "MIT",
66
"peerDependencies": {

packages/router-component-store/src/lib/classic-routed-component-test.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async function setup({
8888
`,
8989
})
9090
class ClassicRoutedComponent {
91-
id$: Observable<string>;
91+
id$: Observable<string | undefined>;
9292
url$: Observable<string>;
9393

9494
constructor(routerStore: RouterStore) {

packages/router-component-store/src/lib/global-router-store/global-router-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ export class GlobalRouterStore
7777
})
7878
);
7979

80-
selectQueryParam<TValue>(param: string): Observable<TValue> {
80+
selectQueryParam(param: string): Observable<string | undefined> {
8181
return this.select(this.queryParams$, (params) => params[param]);
8282
}
8383

84-
selectRouteParam<TValue>(param: string): Observable<TValue> {
84+
selectRouteParam(param: string): Observable<string | undefined> {
8585
return this.select(this.routeParams$, (params) => params[param]);
8686
}
8787
}

packages/router-component-store/src/lib/local-router-store/local-router-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ export class LocalRouterStore
7373
})
7474
);
7575

76-
selectQueryParam<TValue>(param: string): Observable<TValue> {
76+
selectQueryParam(param: string): Observable<string | undefined> {
7777
return this.select(this.queryParams$, (params) => params[param]);
7878
}
7979

80-
selectRouteParam<TValue>(param: string): Observable<TValue> {
80+
selectRouteParam(param: string): Observable<string | undefined> {
8181
return this.select(this.routeParams$, (params) => params[param]);
8282
}
8383
}

packages/router-component-store/src/lib/router-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export abstract class RouterStore {
6565
* @example <caption>Usage</caption>
6666
* const order$ = routerStore.selectQueryParam('order');
6767
*/
68-
abstract selectQueryParam<TValue>(param: string): Observable<TValue>;
68+
abstract selectQueryParam(param: string): Observable<string | undefined>;
6969
/**
7070
* Select the specified route parameter.
7171
*
@@ -74,5 +74,5 @@ export abstract class RouterStore {
7474
* @example <caption>Usage</caption>
7575
* const id$ = routerStore.selectRouteParam('id');
7676
*/
77-
abstract selectRouteParam<TValue>(param: string): Observable<TValue>;
77+
abstract selectRouteParam(param: string): Observable<string | undefined>;
7878
}

packages/router-component-store/src/lib/standalone-routed-component-test.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async function setup({
8787
`,
8888
})
8989
class StandaloneRoutedComponent {
90-
id$: Observable<string>;
90+
id$: Observable<string | undefined>;
9191
url$: Observable<string>;
9292

9393
constructor(routerStore: RouterStore) {

0 commit comments

Comments
 (0)