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

Typescrpt error when try to have a computed value derived from another computed #192

Closed
Nunatic02 opened this issue Jul 28, 2021 · 2 comments
Labels
wontfix This will not be worked on

Comments

@Nunatic02
Copy link

const state = proxyWithComputed<{ count: number }, { doubled: number, quadrupled: number }>({
  count: 1,
}, {
  doubled: snap => snap.count * 2,
  quadrupled: snap => snap.doubled * 2
})

will result in typescript error Property 'doubled' does not exist on type '{ count: number; }'.

@dai-shi
Copy link
Member

dai-shi commented Jul 28, 2021

Thanks for reporting. This is a limitation in types. (I think it's impossible, but would like to hear from TS experts.)

A workaround would only be type assertion.

const state = proxyWithComputed<{ count: number }, { doubled: number, quadrupled: number }>({
  count: 1,
}, {
  doubled: snap => snap.count * 2,
  quadrupled: snap => (snap as { count: number; doubled: number }).doubled * 2
})

https://codesandbox.io/s/trusting-bas-doyoq?file=/src/App.tsx

@dai-shi
Copy link
Member

dai-shi commented Aug 10, 2021

Closing this as it's not possible in TS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants