Skip to content

Type issue to unwrap the inner reactive variables #5610

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

Closed
Oleksii14 opened this issue Mar 21, 2022 · 2 comments
Closed

Type issue to unwrap the inner reactive variables #5610

Oleksii14 opened this issue Mar 21, 2022 · 2 comments

Comments

@Oleksii14
Copy link

Version

3.2.31

Reproduction link

github.com

Steps to reproduce

  1. Clone the attached repo
  2. npm i
  3. Open App.vue file
  4. See the TypeScript error on line 14

What is expected?

No TypeScript error appears while trying to use the reactive variables as values for the reactive objects with generic type

What is actually happening?

The current type description of reactive does not cover the case when there is a need to use Ref inside typed reactive


Since any usage of reactive variables is unwrapped inside reactive, the current type does not cover the described case

@Oleksii14
Copy link
Author

Oleksii14 commented Mar 21, 2022

Related to #963

@LinusBorg
Copy link
Member

LinusBorg commented Mar 21, 2022

The generic describes the shape of the object you pass to reactive().

Your problem is that the interface doesn't properly describe the object that you pass in: the interface doesn't account for the ref. Ref<number> would be accurate.

or you do this instead:

> const form: Form = reactive({
  a: 1,
  // ts error
  b: counter
})

because the return value of reactive has refs unwrapped, so it matches the desired interface shape.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants