qwik icon indicating copy to clipboard operation
qwik copied to clipboard

[🐞] type error when the `requestEvent.fail()` is returned in the `actionQrl` or `loaderQrl`

Open wtlin1228 opened this issue 2 years ago • 0 comments

Which component is affected?

Qwik City (routing)

Describe the bug

routeAction$, globalAction$ and routeLoader$ have incorrect type when the requestEvent.fail(...) is returned in the actionQrl or loaderQrl.

ex:

export const useRouteActionWithFail = routeAction$((data, requestEvent) => {
  if (Math.random() > 1) {
    return requestEvent.fail(500, {
      sad: 'sad',
      errorMessage: 'why',
    });
  } 

  return {
    happy: 'happy',
    day: 'day',
  };
});

const Foo = Component$(() => {
  const routeActionWithFail = useRouteActionWithFail();
  routeActionWithFail.value?.happy; // ❌ Property 'happy' does not exist on type 'FailReturn<...>'
  routeActionWithFail.value?.day; // ❌ Property 'day' does not exist on type 'FailReturn<...>'
  routeActionWithFail.value?.sad; // ❌ Property 'sad' does not exist on type 'FailReturn<...>'
  routeActionWithFail.value?.errorMessage; // ❌ Property 'errorMessage' does not exist on type 

  return <></>
})

Reproduction

https://github.com/wtlin1228/qwik-issue-server-functions

Steps to reproduce

  • npm install
  • open src/routes/index.tsx then you can see the type error

System Info

System:
    OS: macOS 12.5.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 32.27 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.1.3 - ~/.nvm/versions/node/v16.17.0/bin/npm
  Browsers:
    Chrome: 112.0.5615.137
    Edge: 112.0.1722.64
    Firefox: 89.0.2
    Safari: 15.6.1
    Safari Technology Preview: 16.0
  npmPackages:
    @builder.io/qwik: 0.105.0 => 0.105.0
    @builder.io/qwik-city: ~0.104.0 => 0.104.0
    undici: 5.22.0 => 5.22.0
    vite: 4.3.3 => 4.3.3

Additional Information

I am currently working on resolving an issue in the following Pull Request: https://github.com/BuilderIO/qwik/pull/3977. However, I have one error left with useUndefined. My approach might be considered a workaround, so I would appreciate it if you could provide a cleaner solution from a higher-level perspective. Or give me some advise so I can keep going with my PR.

wtlin1228 avatar Apr 29 '23 22:04 wtlin1228