sveltejs / sapper

The next small thing in web development, powered by Svelte
https://sapper.svelte.dev
MIT License
7k stars 434 forks source link

Typescript issues with v0.29.0 (tested in sveltejs/sapper-template) #1706

Closed motzyball closed 3 years ago

motzyball commented 3 years ago

Describe the bug I upgraded Sapper in a new sveltejs/sapper-template rollup project and see Typescript errors when running npm i && npm run dev

Logs

(Repeated for client, server, and service-worker)

@rollup/plugin-typescript TS2769: No overload matches this call.
  Overload 1 of 2, '(...handlers: RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]): Polka', gave the following error.
    Argument of type '(req: SapperRequest, res: SapperResponse, next: () => void) => void' is not assignable to parameter of type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.
      Types of parameters 'req' and 'req' are incompatible.
        Property 'search' is missing in type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' but required in type 'SapperRequest'.
  Overload 2 of 2, '(pattern: string | RegExp, ...handlers: RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[] | Polka[]): Polka', gave the following error.
    Argument of type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' is not assignable to parameter of type 'string | RegExp'.
      Type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' is missing the following properties from type 'RegExp': exec, test, source, global, and 12 more.

  9 polka() // You can also use Express
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 10  .use(
    ~~~~~~
... 
 13      sapper.middleware()
    ~~~~~~~~~~~~~~~~~~~~~
 14  )
    ~~

  src/node_modules/@sapper/index.d.ts:62:3
    62      search: string | null;
            ~~~~~~
    'search' is declared here.

To Reproduce

Information about your Sapper Installation:

npx envinfo --system --npmPackages svelte,sapper,rollup,webpack --binaries --browsers
npx: installed 1 in 1.233s

  System:
    OS: macOS 10.15.7
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 35.42 GB / 64.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.20.1 - ~/.nvm/versions/node/v12.20.1/bin/node
    npm: 6.14.10 - ~/.nvm/versions/node/v12.20.1/bin/npm
  Browsers:
    Chrome: 87.0.4280.141
    Firefox: 84.0.2
    Safari: 13.1.3
  npmPackages:
    rollup: ^2.3.4 => 2.38.0 
    sapper: ^0.29.0 => 0.29.0 
    svelte: ^3.17.3 => 3.31.2 

Severity Blocking upgrade, which is important for us because it seems to fix issues we have with preload not firing consistently (https://github.com/sveltejs/sapper/issues/1582)

Jayphen commented 3 years ago

I created an issue in the sapper-template repo here as I'm experiencing the same: https://github.com/sveltejs/sapper-template/issues/300

I had thought this was just an incompatibility with the Express types, but I guess it happens with polka too.

@motzyball You can cast sapper.middleware() as any to allow it to build; it doesn't have to be a blocking upgrade (depending on how strict your ts config is)

dummdidumm commented 3 years ago

Seems like the typings for that changed in #1604 . The quick fix for this issue might be to make search optional, although I don't know if that's semantically correct (don't know much of the Sapper typings). If that fixes the other liked error - I don't know, because the error message does not say why the other overloads don't apply.

letmejustputthishere commented 3 years ago

I'm still experiencing this. Steps to reproduce:

npx degit "sveltejs/sapper-template#rollup" my-app
cd my-app
node scripts/setupTypeScript.js
npm install
npm run dev

Leads to:

• service worker
@rollup/plugin-typescript TS2769: No overload matches this call.
  Overload 1 of 2, '(pattern: string | RegExp, ...handlers: (Polka<Request> | Middleware<Request>)[]): Polka<Request>', gave the following error.
    Argument of type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' is not assignable to parameter of type 'string | RegExp'.
      Type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' is missing the following properties from type 'RegExp': exec, test, source, global, and 12 more.
  Overload 2 of 2, '(...handlers: (Polka<Request> | Middleware<Request>)[]): Polka<Request>', gave the following error.
    Argument of type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' is not assignable to parameter of type 'Polka<Request> | Middleware<Request>'.
      Type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' is not assignable to type 'Middleware<Request>'.
        Types of parameters 'req' and 'req' are incompatible.
          Type 'Request' is missing the following properties from type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>': get, header, accepts, acceptsCharsets, and 21 more.

11   compression({ threshold: 0 }),
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@rollup/plugin-typescript TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type '(err: any) => void' is not assignable to parameter of type 'ListenCallback'.

15  .listen(PORT, err => {
                  ~~~~~~~~

  node_modules/polka/index.d.ts:61:2
    61  listen(handle: any, callback?: ListenCallback): this;
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The last overload is declared here.