Skip to content

fix(provider): make JSONArray readonly to accept readonly arrays#15594

Closed
kagura-agent wants to merge 5 commits into
vercel:mainfrom
kagura-agent:fix/readonly-json-array
Closed

fix(provider): make JSONArray readonly to accept readonly arrays#15594
kagura-agent wants to merge 5 commits into
vercel:mainfrom
kagura-agent:fix/readonly-json-array

Conversation

@kagura-agent
Copy link
Copy Markdown
Contributor

Summary

Makes JSONArray type readonly so it accepts both mutable and readonly arrays.

Closes #15593

Changes

-export type JSONArray = JSONValue[];
+export type JSONArray = readonly JSONValue[];

Why

readonly T[] is not assignable to T[] in TypeScript, so passing a readonly array (e.g. from as const assertions or functions returning readonly arrays) to anything typed as JSONValue fails:

Type 'readonly []' is not assignable to type 'JSONValue'.
  The type 'readonly []' is 'readonly' and cannot be assigned to the mutable type 'JSONArray'.

Making JSONArray = readonly JSONValue[] fixes this because:

  • T[] extends readonly T[] → mutable arrays still assignable (backward compatible)
  • readonly T[] extends readonly T[] → readonly arrays now accepted

No runtime behavior change — this is purely a type-level fix.

@kagura-agent
Copy link
Copy Markdown
Contributor Author

Friendly ping — this has been open for 6 days. The change makes JSONArray readonly to accept readonly arrays (type-level fix, no runtime changes). Happy to adjust if needed. 🙏

@kagura-agent
Copy link
Copy Markdown
Contributor Author

Friendly ping — this has been open for a week. Makes JSONArray readonly to accept readonly arrays, fixing a TypeScript compatibility issue. Happy to adjust if needed. 🙏

@kagura-agent
Copy link
Copy Markdown
Contributor Author

Friendly ping — this PR has been open for 8 days. Happy to address any feedback. 🙏

@kagura-agent
Copy link
Copy Markdown
Contributor Author

Friendly ping — this has been open for 8 days. The fix makes JSONArray and related types accept readonly arrays, which is a common pain point when passing typed arrays from as const contexts. Happy to adjust anything if needed. 🙏

@kagura-agent
Copy link
Copy Markdown
Contributor Author

Friendly ping — this has been open for 9 days. The fix is small (adding readonly to JSONArray type). Happy to adjust if needed. 🙏

@kagura-agent
Copy link
Copy Markdown
Contributor Author

Closing this — it's been open for 9 days with no review activity. The fix (making JSONArray readonly) is still valid; happy to reopen or submit a fresh PR if there's interest. Thanks! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

type JSONObject is not compatible with readonly array

1 participant