Skip to content

Conversation

jerelmiller
Copy link

@jerelmiller jerelmiller commented Sep 20, 2025

Take the following:

declare const chunk: FormattedIncrementalResult<Record<string, unknown>>;

if ("items" in chunk) {
  const { items } = chunk;

  // TypeScript error
  items.slice(0);
}

When providing a generic to *IncrementalResult, the items property on *IncrementalStreamResult is typed incorrect due to the Array<*> being part of the default type instead of the items property. This means calling array methods on items results in a TypeScript error since TypeScript doesn't know its an array. This is incorrect since items can only be an array type and nothing else. Here is the reproduction in TS Playground.

This PR fixes this issue by moving the Array<*> wrapper to the items type so that this works as expected.

@jerelmiller jerelmiller requested a review from a team as a code owner September 20, 2025 20:47
> {
errors?: ReadonlyArray<GraphQLFormattedError>;
items: TData;
items: ReadonlyArray<TData>;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything else seems to use ReadonlyArray, so I figured this should probably be the same instead of Array like it was before.

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.

1 participant