Skip to content

Commit 2d2e244

Browse files
authored
[react] Fix invalid readonly array value in ServerContextJSONArray (DefinitelyTyped#65149)
* fix invalid readonly array value * add unit test * add nested array test
1 parent 04c9ac7 commit 2d2e244

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

types/react/next.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ declare module '.' {
5555

5656
export function use<T>(usable: Usable<T>): T;
5757

58-
interface ServerContextJSONArray extends ReadonlyArray<ServerContextJSONArray> {}
58+
interface ServerContextJSONArray extends ReadonlyArray<ServerContextJSONValue> {}
5959
export type ServerContextJSONValue =
6060
| string
6161
| boolean

types/react/test/next.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ function serverContextTest() {
4242

4343
// plain objects work
4444
React.createServerContext('PlainObjectContext', { foo: 1 });
45+
// readonly arrays work
46+
React.createServerContext('ReadonlyArrayContext', ['foo', 'bar'] as const);
47+
// nested readonly arrays work
48+
React.createServerContext('ReadonlyArrayContext', ['foo', ['bar']] as const);
4549
// @ts-expect-error Incompatible with JSON stringify+parse
4650
React.createServerContext('DateContext', new Date());
4751
// @ts-expect-error Incompatible with JSON stringify+parse

0 commit comments

Comments
 (0)