Skip to content

Fix ArrayField initialValue type: unknown[] instead of [unknown] - #497

Open
ZayanKhan-12 wants to merge 1 commit into
teslamotors:masterfrom
ZayanKhan-12:arrayfield-initialvalue-type
Open

Fix ArrayField initialValue type: unknown[] instead of [unknown]#497
ZayanKhan-12 wants to merge 1 commit into
teslamotors:masterfrom
ZayanKhan-12:arrayfield-initialvalue-type

Conversation

@ZayanKhan-12

Copy link
Copy Markdown

Problem

#485: ArrayField's initialValue prop is declared as [unknown] in index.d.ts — a single-element tuple — so TypeScript rejects any initial value with more than one item:

error TS2322: Type '[{ name: string; }, { name: string; }]' is not assignable to type '[unknown]'.
  Source has 2 element(s) but target allows only 1.

This rejects the exact usage shown in the ArrayField docs.

Changes

  • index.d.ts: initialValue?: [unknown]initialValue?: unknown[], as suggested in the issue.
  • index.test-d.tsx: the existing ArrayField type test used a one-element array, which a tuple type accidentally accepts — that's why this slipped through. It now uses a two-element initialValue, so reintroducing the tuple type fails the tsd run.

Verification

Compiling an assignment of a two-element array to Props['initialValue'] fails against the old declaration with the exact TS2322 error above and passes with the fix. (The full local npx tsd run reports 76 pre-existing "Cannot find namespace JSX" errors on unmodified master as well — an environment/@types/react drift unrelated to this change; the error count is identical before and after.)

Fixes #485

🤖 Generated with Claude Code

The declared type [unknown] is a single-element tuple, so TypeScript
rejected any ArrayField initialValue with more than one item, including
the example from the docs (teslamotors#485). The type test only used a one-element
array, which a tuple type accidentally accepts; it now uses two items
so a regression fails the tsd run.

Fixes teslamotors#485

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

ArrayField initialValue prop type is not correct

1 participant