sveltejs / sapper

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

Build not working in Typescript #1761

Open incompletude opened 3 years ago

incompletude commented 3 years ago

First-time Svelte user.

Tried to follow the docs for a typescript project, and it doesn't work. Multiple warnings on build, multiple warning and errors on run.

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.

Come on guys, I understand Sapper is in early development, and some things may change before we hit version 1.0., but the very Getting started must work.

Also, linting should be available out of the box.

philippone commented 3 years ago

Hi,

I did the following changes to src/server.ts and at least it's compiling without errors.

polka() // You can also use Express
    .use(
        // compression({ threshold: 0 }),
        sirv('static', { dev }),
        sapper.middleware()
    )
    // .listen(PORT, err => {
        //  if (err) console.log('error', err);
        // });
        .listen(PORT);

Not sure what I removed actually.

incompletude commented 3 years ago

I just dropped the idea of using Stelve/Sapper. Not mature enough. Thx anyway.

Oliver-Piorun commented 3 years ago

Hi! The issue seems to be related to polka. Version 1.0.0-next.11 works just fine, 1.0.0-next.12 breaks it.

The newer version introduced typings for use and listen which are not compatible with the template anymore: https://github.com/lukeed/polka/compare/v1.0.0-next.11...v1.0.0-next.12#diff-c1a30fcb84e4afba40aece7b061bcd4223a94bdf8465e4b341e4700cdae53d66R48

Current solution: Stick to 1.0.0-next.11. Further investigation is required ;-)

Greetings! :)