kriasoft / universal-router

A simple middleware-style router for isomorphic JavaScript web apps
https://www.kriasoft.com/universal-router/
MIT License
1.7k stars 103 forks source link

TypeScript 3.8.3: type checking failing #188

Open StefanJelner opened 4 years ago

StefanJelner commented 4 years ago

Description: When compiling Universal Router with Typescript 3.8.3 i get the following type checking errors:

[tsl] ERROR in foo/node_modules/universal-router/src/UniversalRouter.ts(207,13)
      TS2322: Type '{ done: false; value: false | RouteMatch<R, C>; }' is not assignable to type 'IteratorResult<RouteMatch<R, C>, false>'.
  Type '{ done: false; value: false | RouteMatch<R, C>; }' is not assignable to type 'IteratorReturnResult<false>'.
    Types of property 'done' are incompatible.
      Type 'false' is not assignable to type 'true'.
foo/node_modules/universal-router/src/UniversalRouter.ts
[tsl] ERROR in foo/node_modules/universal-router/src/UniversalRouter.ts(291,68)
      TS2339: Property 'route' does not exist on type 'false | RouteMatch<R, C>'.
  Property 'route' does not exist on type 'false'.
foo/node_modules/universal-router/src/UniversalRouter.ts
[tsl] ERROR in foo/node_modules/universal-router/src/UniversalRouter.ts(294,81)
      TS2339: Property 'route' does not exist on type 'false | RouteMatch<R, C>'.
  Property 'route' does not exist on type 'false'.
foo/node_modules/universal-router/src/UniversalRouter.ts
[tsl] ERROR in foo/node_modules/universal-router/src/UniversalRouter.ts(299,65)
      TS2339: Property 'route' does not exist on type 'false | RouteMatch<R, C>'.
  Property 'route' does not exist on type 'false'.
foo/node_modules/universal-router/src/UniversalRouter.ts
[tsl] ERROR in foo/node_modules/universal-router/src/UniversalRouter.ts(314,69)
      TS2339: Property 'params' does not exist on type 'false | RouteMatch<R, C>'.
  Property 'params' does not exist on type 'false'.

Solution: I already fixed it and attached a git diff to this bug report. UniversalRouter.ts.txt

frenzzy commented 4 years ago

Can you please share the code how you are using it, for example how your routes looks like?

StefanJelner commented 4 years ago

These errors are build errors, which are related to wrong or incomplete type declarations in your code, which have nothing to do with the way my routes look like. Please check the diff i made.

frenzzy commented 4 years ago

I do not have any type errors in my codebase and I am not sure you solution is correct. Could you please share a minimal working example that I can reproduce the issue?

Maybe something wrong with tsconfig 🤷‍♂️

StefanJelner commented 4 years ago

It worked until i updated your library. So it must have to do with changes you made in your library. It is easy to reproduce. Use Typescript 3.8.3 and import your library. Actually the errors should come up. Already in your IDE if you use VSC.

frenzzy commented 4 years ago

I just created a playground repo: https://github.com/frenzzy/universal-router-playground There are no type errors, could you please tell me what I should change to reproduce the issue?

frenzzy commented 4 years ago

@StefanJelner any clue?

GordonSmith commented 4 years ago

@frenzzy reproduced example: https://github.com/frenzzy/universal-router-playground/pull/1

(Apologies for the additional noise in the PR, it was cut and paste from a larger project).

The issue only presents itself after the generateUrls import is added...

Lispython commented 3 years ago

@frenzzy hi, I have the same problem with typescript 4.2.4 and I can confirm that bug appears after generateUrls import is added. Do you have any idea how to fix it?

mbeckert commented 2 years ago

@frenzzy i'm experiencing the same problem with typescript 4.4.4, when importing generateUrls - any news? @Lispython @GordonSmith @StefanJelner where you able to fix it in your project?