blitz-js / legacy-framework

MIT License
3 stars 2 forks source link

Route manifest types don't handle routes with a single optional param #381

Closed Nfinished closed 2 years ago

Nfinished commented 2 years ago

What is the problem?

For a route like this:

projects/
   [[...projectId]].tsx

projects/, projects/1234, and projects/edit/1234 should be equally valid. But as seen in the error logs below, tsc requires that the ProjectsPage route have an id param. I'm pretty sure that param is the wrong type too, (string | number)[] is too narrow when string and number should also be valid.

Paste all your error logs here:

app/core/layouts/AppLayout.tsx:23:45 - error TS2554: Expected 1 arguments, but got 0.

23     () => router.pathname.startsWith(Routes.ProjectsPage().pathname),
                                               ~~~~~~~~~~~~

  node_modules/.blitz/index.d.ts:7:14
    7   ProjectsPage(query: { id?: (string | number)[] } & ParsedUrlQueryInput): RouteUrlObject;
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    An argument for 'query' was not provided.

app/core/layouts/AppLayout.tsx:35:30 - error TS2554: Expected 1 arguments, but got 0.

35           <Link href={Routes.ProjectsPage()}>
                                ~~~~~~~~~~~~

  node_modules/.blitz/index.d.ts:7:14
    7   ProjectsPage(query: { id?: (string | number)[] } & ParsedUrlQueryInput): RouteUrlObject;
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    An argument for 'query' was not provided.

app/projects/components/EditProject.tsx:95:27 - error TS2554: Expected 1 arguments, but got 0.

95     router.replace(Routes.ProjectsPage())
                             ~~~~~~~~~~~~

  node_modules/.blitz/index.d.ts:7:14
    7   ProjectsPage(query: { id?: (string | number)[] } & ParsedUrlQueryInput): RouteUrlObject;
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    An argument for 'query' was not provided.

app/projects/components/Project.tsx:161:47 - error TS2322: Type 'number' is not assignable to type '(string | number)[] | undefined'.

161               <Link href={Routes.ProjectsPage({ id })} replace>
                                                  ~~

  node_modules/.blitz/index.d.ts:7:23
    7   ProjectsPage(query: { id?: (string | number)[] } & ParsedUrlQueryInput): RouteUrlObject;
                            ~~
    The expected type comes from property 'id' which is declared here on type '{ id?: (string | number)[] | undefined; } & ParsedUrlQueryInput'

Paste all relevant code snippets here:

What are detailed steps to reproduce this?

1.

Run blitz -v and paste the output here:

macOS Monterey | darwin-x64 | Node: v16.4.2

blitz: 0.43.0 (local)

  Package manager: yarn
  System:
    OS: macOS 12.0.1
    CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
    Memory: 17.47 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.4.2 - /var/folders/34/c8tk0fm52hz6z0288x5npsp80000gp/T/yarn--1638302973768-0.33274331420404146/node
    Yarn: 1.22.17 - /var/folders/34/c8tk0fm52hz6z0288x5npsp80000gp/T/yarn--1638302973768-0.33274331420404146/yarn
    npm: 7.18.1 - ~/.asdf/installs/nodejs/16.4.2/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: 3.5.0 => 3.5.0
    blitz: 0.43.0 => 0.43.0
    prisma: 3.5.0 => 3.5.0
    react: 18.0.0-alpha-5ca4b0433-20211020 => 18.0.0-alpha-5ca4b0433-20211020
    react-dom: 18.0.0-alpha-5ca4b0433-20211020 => 18.0.0-alpha-5ca4b0433-20211020
    typescript: ~4.4 => 4.4.4

Please include below any other applicable logs and screenshots that show your problem:

No response

Nfinished commented 2 years ago

Worth noting that this works as expected in dev so the functionality is there. It's just the stricter types during build that are wrong.