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

error TS2322 #151

Open
sc0h0 opened this issue Feb 23, 2024 · 6 comments
Open

error TS2322 #151

sc0h0 opened this issue Feb 23, 2024 · 6 comments
Assignees

Comments

@sc0h0
Copy link

sc0h0 commented Feb 23, 2024

Anyone receiving this error message? Trying to run on Windows.

src/core.ts:87:44 - error TS2322: Type '(data: ReadonlyDeep<Dictionary | Dictionary[]>, datasetIdOrName?: string | undefined) => Promise<void>' is not assignable to type '(args_0: any, ...args_1: unknown[]) => Promise<void>'.
  Types of parameters 'datasetIdOrName' and 'args_1' are incompatible.
    Type 'unknown' is not assignable to type 'string | undefined'.

87           await config.onVisitPage({ page, pushData });
                                              ~~~~~~~~

  src/config.ts:66:9
    66         pushData: z.function().args(z.any()).returns(z.promise(z.void())),
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The expected type comes from property 'pushData' which is declared here on type '{ page: Page; pushData: (args_0: any, ...args_1: unknown[]) => Promise<void>; }'


Found 1 error in src/core.ts:87

This is the config I am using to test:

image

@moolchand-danny
Copy link

Hey, also having this issue. Any updates on a potential fix?

root@dev-server-ubuntu:/opt/gpt-crawler# npm start

> @builder.io/[email protected] start
> npm run start:dev


> @builder.io/[email protected] start:dev
> cross-env NODE_ENV=development npm run build && node dist/src/main.js


> @builder.io/[email protected] build
> tsc

src/core.ts:88:46 - error TS2322: Type '(data: ReadonlyDeep<Dictionary | Dictionary[]>, datasetIdOrName?: string | undefined) => Promise<void>' is not assignable to type '(args_0: any, ...args_1: unknown[]) => Promise<void>'.
  Types of parameters 'datasetIdOrName' and 'args_1' are incompatible.
    Type 'unknown' is not assignable to type 'string | undefined'.

88             await config.onVisitPage({ page, pushData });
                                                ~~~~~~~~

  src/config.ts:66:9
    66         pushData: z.function().args(z.any()).returns(z.promise(z.void())),
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The expected type comes from property 'pushData' which is declared here on type '{ page: Page; pushData: (args_0: any, ...args_1: unknown[]) => Promise<void>; }'


Found 1 error in src/core.ts:88

@cyberautomate
Copy link

Same error here, the newest build seems to be broken.

@cyberautomate
Copy link

Anyone receiving this error message? Trying to run on Windows.

src/core.ts:87:44 - error TS2322: Type '(data: ReadonlyDeep<Dictionary | Dictionary[]>, datasetIdOrName?: string | undefined) => Promise<void>' is not assignable to type '(args_0: any, ...args_1: unknown[]) => Promise<void>'.
  Types of parameters 'datasetIdOrName' and 'args_1' are incompatible.
    Type 'unknown' is not assignable to type 'string | undefined'.

87           await config.onVisitPage({ page, pushData });
                                              ~~~~~~~~

  src/config.ts:66:9
    66         pushData: z.function().args(z.any()).returns(z.promise(z.void())),
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The expected type comes from property 'pushData' which is declared here on type '{ page: Page; pushData: (args_0: any, ...args_1: unknown[]) => Promise<void>; }'


Found 1 error in src/core.ts:87

This is the config I am using to test:

image

v1.3.0 seems to work fine for me. https://github.com/BuilderIO/gpt-crawler/archive/refs/tags/v1.3.0.zip

@RobinJauffret
Copy link

I have the same issue if I update the dependancies with a "npm update/upgrade", otherwise, it works well.

@bhuynhdev
Copy link

bhuynhdev commented Mar 29, 2024

Can confirm that this also happens to me on latest version. I have a temporary fix; unsure if this is correct though because so many .any().

I found out that this happens because the Zod schema for the Config file (in the config.ts file was slightly wrong). Specifically, the pushData function that is passed in await config.onVisitPage({ page, pushData }) comes from PlaywrightCrawler and should have 2 arguments.

Therefore, I fixed it in the config.ts file so that it also reflects the "pushData function have 2 args" in the Config type:

  onVisitPage: z
    .function()
    .args(
      z.object({
        page: Page,
        pushData: z.function().args(z.any(), z.any().optional()).returns(z.promise(z.void())), // Two function args
      }),
    )
    .returns(z.promise(z.void()))
    .optional(),

@guoxin12980
Copy link

Same issues
image

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

No branches or pull requests

7 participants