Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type definition on Dataset.reduce does not match documented (and implemented) behaviour #2773

Open
1 task
halvko opened this issue Dec 16, 2024 · 0 comments · May be fixed by #2774
Open
1 task

Type definition on Dataset.reduce does not match documented (and implemented) behaviour #2773

halvko opened this issue Dec 16, 2024 · 0 comments · May be fixed by #2774
Assignees
Labels
bug Something isn't working. t-tooling Issues with this label are in the ownership of the tooling team.

Comments

@halvko
Copy link

halvko commented Dec 16, 2024

Which package is this bug report for? If unsure which one to select, leave blank

@crawlee/core

Issue description

According to the documentation "If no memo is passed to the initial invocation of reduce, the iteratee() is not invoked on the first element of the list. The first element is instead passed as the memo in the invocation of the iteratee() on the next element in the list.". But according to the type definitions, reduces second parameter is non-optional, and all items will be of the same type as the parameter passed (e.g. If one passes undefined, the type of the item will be undefined even though it should be Data).

Code sample

const dataset = Dataset.open(/* some dataset id */)

// Causes type-error: `Expected 2-3 arguments, but got 1`
dataset.reduce(async (acc, next) => {
   next 
});

// Causes type-error: `Type 'Promise<Dictionary>' is not assignable to type 'Awaitable<undefined>'` with a ton of explanation - the problem is that the type of `next` is `Dictionary`, whereas reduce is expecting the function to return an `undefined`
dataset.reduce(async (acc, next) => {
   next 
}, undefined);

Package version

upstream

Node.js version

N/A

Operating system

N/A

Apify platform

  • Tick me if you encountered this issue on the Apify platform

I have tested this on the next release

upstream

Other context

No response

@halvko halvko added the bug Something isn't working. label Dec 16, 2024
@github-actions github-actions bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Dec 16, 2024
@halvko halvko linked a pull request Dec 16, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. t-tooling Issues with this label are in the ownership of the tooling team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants