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

toRef<MaybeRef> - can't assign to value in TS #12986

Open
Maxim-Mazurok opened this issue Mar 3, 2025 · 2 comments · May be fixed by #12996
Open

toRef<MaybeRef> - can't assign to value in TS #12986

Maxim-Mazurok opened this issue Mar 3, 2025 · 2 comments · May be fixed by #12996

Comments

@Maxim-Mazurok
Copy link

Vue version

3.5.13

Link to minimal reproduction

https://play.vuejs.org/#eNrNVE2P2jAQ/SsjXwAJBQG7PbCA1FZ72ErdrXY5Wlo5yRBMEzuyHT5E+e8dO2xIBdr2Umkv0djz5s3zm9gH9rkso02FbMKmNjGydGDRVSXkQmUzzpzlbM6VLEptHBzA6Wdc9uG72McYIuM/FMERlkYX0CGyDldcJVpZB8WecmhQJTicNGVTVRUxmjnMfH13OBr37q5UjCgfGnbbNB7aBkUbkVdI0JvbT3cwGMBiXyJ06hYdkBaUdiCslZkScY5ECS5AXjqR/0CiqzyFGEGSAKGcFA5T2Eq3AqFAmFg6I8y+rtquZLI6l1TKYB7wRPvWNHK2OxqPRj1vRJcrgNdSZPigUtxdutD3oisrVdakuOrBbA4HX1rb0tQ3npwpvSNwRjSGDD+eHUeSesWS9j/xC+oo2PL4tPiP1pRkQ6NJl04S36SmvhiJd0Om6C3Q8RoT9wfx5VSJ9Ph3paemfeCsSXLWC+rq/qlchj/d1RWgN2hyLdJ/O9d0UN9qusO0cFiUfjq0mg5aC9ani04SlzKL1lYreg2Cas4SXZQyR/NU6+TsZI/PiTzX229hz5kK+2/7yQqTn1f215aONqHgh0GLZoOcNTknTIauTt+/POKO4iZZ6LTKCf1O8hmtziuvsYZ9qVRKslu4oPYhvGNk68Le7xzSRE+H8kI98hjwnNEr9vWdo5/ljqObUEd2k4uvNBzPSQaOo9toOGbH3883z58=

Steps to reproduce

Just observe TS errors on lines 6 and 12 of repro

Basically, toRef(MaybeRef<number>).value has this type Ref<T = any, S = T>.value: S = T instead of roughly number

What is expected?

No TS errors

What is actually happening?

TS errors:

Type 'number' is not assignable to type 'S'.
  'S' could be instantiated with an arbitrary type which could be unrelated to 'number'.ts(2322)

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (20) x64 12th Gen Intel(R) Core(TM) i9-12900H
    Memory: 26.21 GB / 31.19 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm
    pnpm: 9.4.0 - ~/.local/share/pnpm/pnpm
  Browsers:
    Chrome: 131.0.6778.264
  npmPackages:
    vue: ^3.5.13 => 3.5.13

Any additional comments?

The issue seems to be resolved in TypeScript Version 5.4.0-beta and later.

@edison1105
Copy link
Member

It can't reproduce with ts v4.9.5, see playground
So it should be a ts bug and resolved in 5.4.0-beta and later.

@edison1105 edison1105 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 4, 2025
@Maxim-Mazurok
Copy link
Author

Hey @edison1105 looks like playground link doesn't include TS version.
I get reproduction with TS 5.1.6:

Image

Which means that the latest Vue version should have peer dependency of TS 5.4.0-beta or later, IMO.

So please, reopen the issue, cheers!

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

Successfully merging a pull request may close this issue.

3 participants