diff --git a/.changeset/fresh-pugs-relax.md b/.changeset/fresh-pugs-relax.md new file mode 100644 index 0000000000..2c98b6c1f6 --- /dev/null +++ b/.changeset/fresh-pugs-relax.md @@ -0,0 +1,5 @@ +--- +"react-router": patch +--- + +Maintain `ReadonlyMap` and `ReadonlySet` types in server response data. diff --git a/contributors.yml b/contributors.yml index cfbb9400d8..5ad6440c45 100644 --- a/contributors.yml +++ b/contributors.yml @@ -47,6 +47,7 @@ - BDomzalski - bhbs - bilalk711 +- bjohn465 - bobziroll - bravo-kernel - Brendonovich diff --git a/packages/react-router/lib/types/route-data.ts b/packages/react-router/lib/types/route-data.ts index 9dc2b6b4da..fae6eb1d5c 100644 --- a/packages/react-router/lib/types/route-data.ts +++ b/packages/react-router/lib/types/route-data.ts @@ -25,7 +25,9 @@ type Serialize = // Map & Set T extends Map ? Map, Serialize> : + T extends ReadonlyMap ? ReadonlyMap, Serialize> : T extends Set ? Set> : + T extends ReadonlySet ? ReadonlySet> : // Array T extends [] ? [] : @@ -108,6 +110,25 @@ type __tests = [ > >, Expect { a: string } | Response>, { a: string }>>, + Expect< + Equal< + ServerDataFrom< + () => { + map: Map; + readonlyMap: ReadonlyMap; + } + >, + { map: Map; readonlyMap: ReadonlyMap } + > + >, + Expect< + Equal< + ServerDataFrom< + () => { set: Set; readonlySet: ReadonlySet } + >, + { set: Set; readonlySet: ReadonlySet } + > + >, // ClientDataFrom Expect, undefined>>,