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

UserData Generic for router #1477

Closed
mstephen19 opened this issue Aug 23, 2022 · 0 comments · Fixed by #1547
Closed

UserData Generic for router #1477

mstephen19 opened this issue Aug 23, 2022 · 0 comments · Fixed by #1547
Assignees
Labels
feature Issues that represent new features or improvements to existing features.

Comments

@mstephen19
Copy link
Contributor

Right now, we are able to define the type of the userData object when creating a request/adding it to a request queue, but can't pass a generic to routerInstance.addHandler.

Here is what we have to do right now:

router.addHandler(Labels.PRODUCTS, async ({ $, request: { userData }, crawler }) => {
    const { dispensaryId, customerType, page, cookie, name } = userData as {
        dispensaryId: string;
        page: number;
        cookie: string;
        name: CustomerTypes;
        customerType: CustomerTypes;
    };
   // ...

Or this works:

router.addHandler(Labels.PRODUCTS, async ({ $, request: { userData }, crawler }: CheerioCrawlingContext<{ dispensaryId: string, /* etc. */ }>) => {
    const { dispensaryId, customerType, page, cookie, name } = userData
    // ...

But as a generic to the addHandler function it would be better:

router.addHandler<{ dispensaryId: string /* etc. */ }>(Labels.PRODUCTS, async ({ $, request: { userData }, crawler }) => {
    const { dispensaryId, customerType, page, cookie, name } = userData
    // ...
@mstephen19 mstephen19 added the feature Issues that represent new features or improvements to existing features. label Aug 23, 2022
@szmarczak szmarczak self-assigned this Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Issues that represent new features or improvements to existing features.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants