remix-run / react-router

Declarative routing for React
https://reactrouter.com
MIT License
53.02k stars 10.3k forks source link

[Bug]: 1.0.3 and 1.0.2 typescript errors #9569

Closed illume closed 1 year ago

illume commented 1 year ago

What version of React Router are you using?

1.0.3 and 1.0.2 typescript errors

Steps to Reproduce

I had two typescript errors with 1.0.3 not in 1.0.1. 1.0.2 only had the second of the errors(the ts-expect-error one below).

I guess it may be something to do with the v5 compatibility types, but don't really know the codebase.

Haven't been able to narrow it down further than below, sorry. (I expect this won't be useful, but it's the best I can do).

https://github.com/kinvolk/headlamp/commit/efedf186e0d3aaf443385d49fa722e059c3eb01e
cd plugins/headlamp-plugin/
./test-headlamp-plugin.js

Expected Behavior

No typescript errors.

Actual Behavior

node_modules/@remix-run/router/router.ts:2947:3 - error TS2322: Type 'boolean | import(".../node_modules/@remix-run/router/utils").ResultType' is not assignable to type 'boolean'.
  Type 'import(".../node_modules/@remix-run/router/utils").ResultType' is not assignable to type 'boolean'.

2947   return (
       ~~~~~~~~
2948     obj &&
     ~~~~~~~~~~
 ...
2950     (obj.type === ResultType.data || ResultType.error)
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2951   );
     ~~~~

node_modules/@remix-run/router/utils.ts:400:9 - error TS2578: Unused '@ts-expect-error' directive.

400         // @ts-expect-error
            ~~~~~~~~~~~~~~~~~~~

Found 2 errors in 2 files.

Errors  Files
     1  node_modules/@remix-run/router/router.ts:2947
     1  node_modules/@remix-run/router/utils.ts:400
timdorr commented 1 year ago

It appears you're importing the @remix-run/router files directly from the package. Instead, only import from the top-level package (just @remix-run/router), as you will not get the transpiled code and separate type defs.