graphql-js
graphql-js copied to clipboard
Adjust `items` type for `IncrementalStreamResult` and `FormattedIncrementalStreamResult`
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.