[๐] Type inference for the return type of the `routeLoader$` is skewed.
genki opened this issue ยท 1 comments
genki commented
Which component is affected?
Qwik Runtime
Describe the bug
I am making Qwik app that uses the modular-form, I found the route loaders can't be used for the loader option of useForm
by type mismatch if their return type are union type.
Here's an example:
export const useFoo = routeLoader$(() => {
const num = Math.random();
return num < 0.5 ? true : undefined;
})
export default component$(() => {
const foo = useFoo();
type Foo = typeof foo;
// ^? type Foo = Readonly<Signal<undefined>> | Readonly<Signal<true>>
return (
I expected the type of Foo
is Readonly<Signal<true|undefined>>
.
Reproduction
https://stackblitz.com/edit/github-gerwzj?file=src%2Froutes%2Findex.tsx
Steps to reproduce
No response
System Info
System:
OS: macOS 14.5
CPU: (8) arm64 Apple M2
Memory: 122.13 MB / 24.00 GB
Shell: 3.6.1 - /opt/homebrew/bin/fish
Binaries:
Node: 20.12.1 - /opt/homebrew/opt/node@20/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 10.5.0 - /opt/homebrew/opt/node@20/bin/npm
pnpm: 9.6.0 - ~/Library/pnpm/pnpm
bun: 1.1.21 - ~/.bun/bin/bun
Browsers:
Chrome: 127.0.6533.120
Safari: 17.5
npmPackages:
@builder.io/qwik: link:../test/qwik/packages/qwik => 1.8.0
@builder.io/qwik-city: link:../test/qwik/packages/qwik-city => 1.8.0
typescript: 5.4.5 => 5.4.5
undici: * => 6.19.5
vite: ^5.2.10 => 5.3.5
Additional Information
No response
genki commented
This may be a problem of the modular-form.