Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

computedAsync without initialState should return union T | undefined #3926

Open
7 tasks done
aphex opened this issue Apr 15, 2024 · 0 comments
Open
7 tasks done

computedAsync without initialState should return union T | undefined #3926

aphex opened this issue Apr 15, 2024 · 0 comments

Comments

@aphex
Copy link

aphex commented Apr 15, 2024

Describe the bug

When using computedAsync in it's basic form:

const g = computedAsync(async () => {
  await new Promise((resolve) => setTimeout(resolve, 5000))

  return 'hello'
})

We get a type of const g: Ref<string>
It would be nice if we could get the type const g: Ref<string | undefined>

Without this the template assumes g will always be a string and TS has no issues.

For example something like this will throw a runtime error (Unhandled error during execution of render function ) but not be caught by typescript

<p>{{ g.charAt(1) }}</p>

Reproduction

https://stackblitz.com/edit/vitejs-vite-hmsvky

System Info

System:
  OS: Windows 11 10.0.22631
  CPU: (32) x64 Intel(R) Core(TM) i9-14900K
  Memory: 32.46 GB / 63.75 GB
Binaries:
  Node: 18.20.0 - ~\AppData\Local\pnpm\node.EXE
  npm: 10.5.0 - ~\AppData\Local\pnpm\npm.CMD
  pnpm: 8.15.7 - ~\AppData\Local\pnpm\pnpm.EXE
Browsers:
  Edge: Chromium (123.0.2420.97)
  Internet Explorer: 11.0.22621.1

Used Package Manager

pnpm

Validations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant