fix: Type flatten as yielding items instead of pages - #1011
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SDK audit finding M11d (medium, type-only):
SeamPaginator.flatten()declared its yield type as the page array while the generator yields single items, sofor await (const device of pages.flatten())typeddeviceasDevice[]while it is aDeviceat runtime. It slipped pasttscbecause the conditional type degrades toanyinside the class. The mistyping also hid a broken README example (console.log(devices.name)inside afor await (const device …)loop).Fix
flatten()now yieldsElementOfArray<TResponse[TResponseKey]>— the item type. Runtime unchanged. Fixed the README example todevice.display_name.Tests
The flatten test now pins the element type:
expectType<Device>(device)compiles andexpectType<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