Skip to content

Feature Proposal: Support val$ Syntax Sugar for ref values #998

Description

@ttv20

Clear and concise description of the problem

I used AI as base because english is not my native language, hope it's not too vorbose

As a developer using Vue Macros, I want a simple syntax sugar (val$) for accessing the .value of a ref, so that I can write cleaner and more readable reactive code without losing explicit control over refs.

I really liked the concept behind the original Reactivity Transform, but in practice, the implementation added too much mental overhead. Remembering when to use $ref, $(), or $$() made code less predictable and harder to follow across files.

This proposal aims to keep the spirit of that transform — removing repetitive .value — but do so in a more lightweight and explicit way, without introducing new macro declarations or hidden behavior.

Suggested solution

In the reactivity transform module (or a new one), we could add a new compile-time transform step that recognizes postfix $ identifiers, such as val$, and rewrites them into <identifier>.value.

How it could work

  • Verify that a binding for the base variable (e.g. val) exists in the current scope.
    Potentially, it could even recognize variables declared in parent scopes or functions (similar to how reactivity transform currently resolves).
  • Rewrite reads, writes, and update expressions accordingly.
  • Leave non-Ref identifiers untouched.
  • Should be adaptable for TypeScript (I assume, I'm not using TS)

Example

<script setup>
import { ref, computed } from 'vue'

const count = ref(0)
const doubled = computed(() => count$ * 2)

function increment() {
  count$++
}

console.log(doubled$) // → doubled.value
</script>

<template>
  <button @click="increment">
    Count: {{ count }} / Doubled: {{ doubled }}
  </button>
</template>

Alternative

val$ can be replaced with $val or with underscore or even with non valid JS char as # or @

Additional context

No response

Validations

Activity

  1. sxzz commented on Sep 28, 2025

    @sxzz
    Member
  2. ttv20 commented on Sep 29, 2025

    @ttv20
    Author

    I believe https://github.com/zhiyuanzmj/unplugin-vue-reactivity-function is what you're looking for.

    No, my idea is much simpler. just convert var with $ at the end of the name and it will be converted to var.value
    You can still use .value, the idea is just to make it shorter and pettier

  3. sxzz commented on Sep 29, 2025

    @sxzz
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions