Skip to content

$$() on array from defineProps yields incorrect Typescript type #6578

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

Open
larrifax opened this issue Sep 1, 2022 · 2 comments
Open

$$() on array from defineProps yields incorrect Typescript type #6578

larrifax opened this issue Sep 1, 2022 · 2 comments

Comments

@larrifax
Copy link

larrifax commented Sep 1, 2022

Vue version

3.2.37

Link to minimal reproduction

https://sfc.vuejs.org/#eNp9Uk1vwjAM/StWhESRoNWuXWFC22HHaddlh664UNR8yElBCPW/z0mhQ2zapart52c/v5zF2tr00KHIReEqaqyHttTbpRTeSQEOfWdXUjfKGvJwhskEeqjJKJCC2zJVVmQY+Si11P5kEd7IWAdLxjqjcE1UnnJwnhq9/fiEnoGV0S5wjXWmXMIG60Zj7C7id5XMIusAH8HvWDN6MknGTIAV2bA97yrmYlh3oUqb7p3RLO4sNfDKQ4H3zSFmQo5lhFiKnffW5Vnm6iqcZO9SQ9uM/1LqtG8UpujU4ovM0SExsRTzG46MkwekBaHeICH9x3kH/cUbaHupe5bybNS9QdGUW5tYNMDVooobOo+bi01T7p2ygdoj1WV19Seqr415unrD0+KJLue2FxePjd+9YF12rXfJXxbNR6ocOpYTEBsmm/1YVzLPdaskmcFyBeGlmHqYknIvo28c5MCjsm3pMUS+2D1EiQCv2LYGjoZangFQZLFSZCNc9N9jb/0F

Steps to reproduce

Reproducing requires full IDE support, so copy the code into your IDE and observe that the type of someArrayRef is Ref<string>[].

Attempting to send the value into a function expecting Ref<string[]> yields the following error message:
Argument of type 'Ref<string>[]' is not assignable to parameter of type 'Ref<string[]>'.

What is expected?

Type of someArrayRef should be Ref<string[]>

What is actually happening?

Type of someArrayRef is Ref<string>[]

System Info

No response

Any additional comments?

I've seen a similar bug report in #5976, but the suggested solution there doesn't seem to yield the same javascript output (and the expected reactivity is lost)

@xsjcTony
Copy link

xsjcTony commented Oct 13, 2022

I cannot find a way to fix it, as it goes for

either $$([a, b]) (e.g. in watch) mentioned in #5976
or the situation discussed above (to keep reactivity for values deconstructed from props)

I tried to add another rule for Arrays
export declare function $$<T extends unknown[]>(value: T): Ref<T>
It does fix the problem here but breaks another one (in #5976)

@xsjcTony
Copy link

xsjcTony commented Oct 13, 2022

I guess just temporarily cast it to the correct type.

const { arr } = defineProps<{ arr: string[] }>()
passAsRef($$(arr) as unknown as Ref<string[]>)

Some thoughts: #6876

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

No branches or pull requests

3 participants