Skip to content

fix: Type flatten as yielding items instead of pages - #1011

Merged
razor-x merged 1 commit into
mainfrom
claude/js-sdk-audit-6x115l-m11d-flatten-type
Aug 24, 2026
Merged

fix: Type flatten as yielding items instead of pages#1011
razor-x merged 1 commit into
mainfrom
claude/js-sdk-audit-6x115l-m11d-flatten-type

Conversation

@razor-x

@razor-x razor-x commented Aug 24, 2026

Copy link
Copy Markdown
Member

Problem

SDK audit finding M11d (medium, type-only): SeamPaginator.flatten() declared its yield type as the page array while the generator yields single items, so for await (const device of pages.flatten()) typed device as Device[] while it is a Device at runtime. It slipped past tsc because the conditional type degrades to any inside the class. The mistyping also hid a broken README example (console.log(devices.name) inside a for await (const device …) loop).

Fix

flatten() now yields ElementOfArray<TResponse[TResponseKey]> — the item type. Runtime unchanged. Fixed the README example to device.display_name.

Tests

The flatten test now pins the element type: expectType<Device>(device) compiles and expectType<Device[]>(device) is a @ts-expect-error. On reverted source, typecheck fails with 3 errors — the audit's exact symptom. Full suite (125 tests), lint, typecheck green.

Part of applying the rev-3 SDK audit (one PR per finding). Related: #1002#1010.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B8xeJm2Hd923k8uo6eoFd2


Generated by Claude Code

The declared yield type of SeamPaginator.flatten was the page array
while the generator yields single items, so iterating flatten typed
each item as an array of the resource. The mistyping also hid a broken
README example that read a property off the wrong variable.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B8xeJm2Hd923k8uo6eoFd2
@razor-x
razor-x requested a review from a team as a code owner August 24, 2026 19:47
@razor-x
razor-x merged commit 7d3a20f into main Aug 24, 2026
16 checks passed
@razor-x
razor-x deleted the claude/js-sdk-audit-6x115l-m11d-flatten-type branch August 24, 2026 23:07
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.

2 participants