fix(types): improve type extraction for namespaced responses and correct async iterator types #637
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.
The
iterator()
function returns an object containing a key ofSymbol.asyncIterator
, which is an object with anext()
function. Only the top-level has theSymbol.asyncIterator
, and thenext()
function is not present at the top-levelThe
GetResultsType<T>
sometimes doesn't return the paginated data and returns the whole data object. For some reason TypeScript sometimes get's confused and returns all the keys in the object in the callKnownKeysMatching<T["data"], any[]>
In order to remedy that, we remove keys that we know do not contain the data (
"repository_selection" | "total_count" | "incomplete_results"
) and we then always get the data.The
NormalizeResponse<T>
type would return the intersection of the original data from the request and the paginated data. To remedy that, we useOmit<T, K>
to remove thedata
from the request data and only return the paginated data instead.Resolves #350
Before the change?
GetResultsType<T>
wouldn't always get the key with the dataAfter the change?
AsyncIterator
vsAsyncIterableIterator
GetResultsType<T>
correctly gets the pagination dataPull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!
While not strictly a breaking change, it can cause breakage to end users as the types have changed.