Skip to content

Commit 06519e2

Browse files
bjohn465pcattori
andauthored
Serialize ReadonlyMap and ReadonlySet types (#13092)
* Add failing tests for ReadonlyMap and ReadonlySet * Add bjohn465 to contributors.yml This is me signing the Contributor License Agreement (CLA). * Add ReadonlyMap and ReadonlySet to Serialize type * Add changeset --------- Co-authored-by: Pedro Cattori <[email protected]>
1 parent d7eb048 commit 06519e2

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

.changeset/fresh-pugs-relax.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-router": patch
3+
---
4+
5+
Maintain `ReadonlyMap` and `ReadonlySet` types in server response data.

contributors.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
- BDomzalski
5353
- bhbs
5454
- bilalk711
55+
- bjohn465
5556
- bmsuseluda
5657
- bobziroll
5758
- bravo-kernel

packages/react-router/lib/types/route-data.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ type Serialize<T> =
3232

3333
// Map & Set
3434
T extends Map<infer K, infer V> ? Map<Serialize<K>, Serialize<V>> :
35+
T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<Serialize<K>, Serialize<V>> :
3536
T extends Set<infer U> ? Set<Serialize<U>> :
37+
T extends ReadonlySet<infer U> ? ReadonlySet<Serialize<U>> :
3638

3739
// Array
3840
T extends [] ? [] :
@@ -230,6 +232,25 @@ type __tests = [
230232
>
231233
>,
232234
Expect<Equal<ServerDataFrom<() => { a: string } | Response>, { a: string }>>,
235+
Expect<
236+
Equal<
237+
ServerDataFrom<
238+
() => {
239+
map: Map<string, number>;
240+
readonlyMap: ReadonlyMap<string, number>;
241+
}
242+
>,
243+
{ map: Map<string, number>; readonlyMap: ReadonlyMap<string, number> }
244+
>
245+
>,
246+
Expect<
247+
Equal<
248+
ServerDataFrom<
249+
() => { set: Set<string>; readonlySet: ReadonlySet<string> }
250+
>,
251+
{ set: Set<string>; readonlySet: ReadonlySet<string> }
252+
>
253+
>,
233254

234255
// ClientDataFrom
235256
Expect<Equal<ClientDataFrom<any>, undefined>>,

0 commit comments

Comments
 (0)