Skip to content

Commit

Permalink
[react] Fix invalid readonly array value in ServerContextJSONArray (D…
Browse files Browse the repository at this point in the history
…efinitelyTyped#65149)

* fix invalid readonly array value

* add unit test

* add nested array test
  • Loading branch information
qucumbah authored Apr 17, 2023
1 parent 04c9ac7 commit 2d2e244
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion types/react/next.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ declare module '.' {

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

interface ServerContextJSONArray extends ReadonlyArray<ServerContextJSONArray> {}
interface ServerContextJSONArray extends ReadonlyArray<ServerContextJSONValue> {}
export type ServerContextJSONValue =
| string
| boolean
Expand Down
4 changes: 4 additions & 0 deletions types/react/test/next.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2d2e244

Please sign in to comment.