-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Array query parameters like `?size=m&size=l&size=xl` are now correctly resolved to `readonly string[]` instead of `string`. **BREAKING CHANGES** `RouterStore#queryParams$` and `MinimalActivatedRouteSnapshot#queryParams` use `StrictQueryParams` instead of `StrictRouteParams`. Members are of type `string | readonly string[] | undefined` instead of `string | undefined`. The TypeScript compiler will fail to compile code that does not handle the string array type. BEFORE: ```typescript // shirts.component.ts // (...) import { RouterStore } from "@ngworker/router-component-store"; @component({ // (...) }) export class ShirtsComponent { #routerStore = inject(RouterStore); size$: Observable<string> = this.#routerStore.queryParams$.pipe( map((params) => params["size"]), ); } ``` AFTER: ```typescript // shirts.component.ts // (...) import { RouterStore } from "@ngworker/router-component-store"; @component({ // (...) }) export class ShirtsComponent { #routerStore = inject(RouterStore); size$: Observable<readonly string[]> = this.#routerStore.queryParams$.pipe( map((params) => params["size"]), map((size) => (Array.isArray(size) ? size : [size])) ); } ``` `RouterStore#selectQueryParam` use `StrictQueryParams` instead of `StrictRouteParams`. The returned value is of type `string | readonly string[] | undefined` instead of `string | undefined`. The TypeScript compiler will fail to compile code that does not handle the string array type. BEFORE: ```typescript // shirts.component.ts // (...) import { RouterStore } from "@ngworker/router-component-store"; @component({ // (...) }) export class ShirtsComponent { #routerStore = inject(RouterStore); size$: Observable<string> = this.#routerStore.selectQueryParam('size'); } ``` AFTER: ```typescript // shirts.component.ts // (...) import { RouterStore } from "@ngworker/router-component-store"; @component({ // (...) }) export class ShirtsComponent { #routerStore = inject(RouterStore); size$: Observable<readonly string[]> = this.#routerStore.selectQueryParam('size').pipe( map((size) => (Array.isArray(size) ? size : [size])) ); } ```
- Loading branch information
Showing
7 changed files
with
41 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
// GlobalRouterStore | ||
// Serializable route state | ||
export * from './lib/@ngrx/router-store/minimal-activated-route-state-snapshot'; | ||
export * from './lib/global-router-store/provide-global-router-store'; | ||
|
||
// LocalRouterStore | ||
export * from './lib/local-router-store/provide-local-router-store'; | ||
|
||
// RouterStore | ||
export * from './lib/router-store'; | ||
|
||
// Serializable route state | ||
export * from './lib/@ngrx/router-store/minimal-activated-route-state-snapshot'; | ||
export * from './lib/strict-query-params'; | ||
export * from './lib/strict-route-data'; | ||
export * from './lib/strict-route-params'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/router-component-store/src/lib/internal-strict-query-params.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Params } from '@angular/router'; | ||
import { StrictNoAny } from './util-types/strict-no-any'; | ||
|
||
/** | ||
* @remarks We use this type to ensure compatibility with {@link Params}. | ||
* @internal | ||
*/ | ||
export type InternalStrictQueryParams = Readonly< | ||
StrictNoAny<Params, string | readonly string[] | undefined> | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/router-component-store/src/lib/strict-query-params.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// [@typescript-eslint/no-unused-vars] Used in TSDoc. | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import { Params } from '@angular/router'; | ||
|
||
/** | ||
* Strict route query {@link Params} with read-only members where the `any` member | ||
* type is converted to `string | readonly string[] | undefined`. | ||
*/ | ||
export interface StrictQueryParams { | ||
readonly [param: string]: string | readonly string[] | undefined; | ||
} |