From 2d2e244fd68b8b1284ebdbf2846fce269a0c8c65 Mon Sep 17 00:00:00 2001 From: Daniil Shmelev <39967396+qucumbah@users.noreply.github.com> Date: Mon, 17 Apr 2023 19:27:57 +0300 Subject: [PATCH] [react] Fix invalid readonly array value in `ServerContextJSONArray` (#65149) * fix invalid readonly array value * add unit test * add nested array test --- types/react/next.d.ts | 2 +- types/react/test/next.tsx | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/types/react/next.d.ts b/types/react/next.d.ts index 81ccab1eadb27a..3e198deebd4c1d 100644 --- a/types/react/next.d.ts +++ b/types/react/next.d.ts @@ -55,7 +55,7 @@ declare module '.' { export function use(usable: Usable): T; - interface ServerContextJSONArray extends ReadonlyArray {} + interface ServerContextJSONArray extends ReadonlyArray {} export type ServerContextJSONValue = | string | boolean diff --git a/types/react/test/next.tsx b/types/react/test/next.tsx index 92e2bb7469178b..dfb600cd2d9dcd 100644 --- a/types/react/test/next.tsx +++ b/types/react/test/next.tsx @@ -42,6 +42,10 @@ function serverContextTest() { // plain objects work React.createServerContext('PlainObjectContext', { foo: 1 }); + // readonly arrays work + React.createServerContext('ReadonlyArrayContext', ['foo', 'bar'] as const); + // nested readonly arrays work + React.createServerContext('ReadonlyArrayContext', ['foo', ['bar']] as const); // @ts-expect-error Incompatible with JSON stringify+parse React.createServerContext('DateContext', new Date()); // @ts-expect-error Incompatible with JSON stringify+parse