Skip to content

fix(language-core): support calling template bindings without .value - #6181

Merged
johnsoncodehk merged 4 commits into
masterfrom
fix/with-dot-value-function-call
Aug 24, 2026
Merged

johnsoncodehk merged 4 commits into
masterfrom
fix/with-dot-value-function-call

Conversation

@johnsoncodehk

@johnsoncodehk johnsoncodehk commented Aug 24, 2026 •

Copy link
Copy Markdown
Member

Problem

Template expressions that reference a setup binding (a "maybe ref" — could be a ref or a plain value) used to always append .value and lean on __VLS_withDotValue to justify it. That assertion is a no-op for function declarations: asserts t is fn & { value: fn } does not add .value to a function, so a function binding became fn.value(...) → TS2339 on an unmapped region → silently dropped, and the call was never type-checked.

Solution

  • generateInterpolation now propagates a call position through the callee subtree. A binding that is being called no longer gets .value, whether the callee is a direct identifier (fn(1)), grouped ((fn)(1)), a logical/binary operand ((fn || g)(1)), a conditional branch, a type assertion, or a tagged-template tag (fn`x`).
  • Property/element-access receivers, call arguments and conditions still get .value.
  • __VLS_withDotValue narrows three cases:
    • non-ref (function or otherwise) → T & { value: T }
    • ref + non-function → T
    • ref + function → T & V (callable)
  • The helper is re-asserted inside event-handler closures, since the top-level assertion does not narrow imported bindings within a closure.
  • {} as Ref → {} as Ref<unknown> so the second argument's value: any no longer leaks into the narrowing of union refs.

Tests

test-workspace/tsc/withDotValue covers @click / {{ }} with a plain function and a ref(fn), including tagged-template call sites and a binding called from two handlers.

Known issue / next step

Value-position function bindings still fail: foo(bar) (argument) and { foo: bar } (shorthand) append .value to bar, and withDotValue cannot add .value to function declarations. The plan is to move read positions to a structural __VLS_unwrap(...) helper — its return type is a conditional, so it works for functions — and keep .value + withDotValue only where narrowing (v-if) or assignment (v-model) is required.

johnsoncodehk and others added 2 commits August 24, 2026 16:08
Template expressions that call a setup binding (e.g. `@click="fn(1)"`)
used to emit `fn.value(1)`, which fails for plain functions and surfaces
as a silently-dropped unmapped diagnostic. Skip the `.value` access for
called bindings, and make `__VLS_withDotValue` narrow ref/function
combinations so the call stays type-checked. Re-assert the helper inside
event handler closures, since the top-level assertion does not narrow
imported bindings within a closure.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes template type-checking for setup bindings that are called (e.g. @click="fn(1)") by preventing unconditional .value insertion on callees and improving __VLS_withDotValue’s narrowing so both plain functions and ref(fn) calls remain type-checked.

Changes:

  • Update template interpolation codegen to avoid appending .value when a setup binding is the callee of a CallExpression, and track “called” bindings.
  • Extend __VLS_withDotValue’s assertion type to correctly narrow non-refs, refs-to-non-functions, and refs-to-functions (callable refs).
  • Add a new withDotValue tsc fixture and expected diagnostics to ensure calls are type-checked in both @click handlers and {{ }} interpolations.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test-workspace/tsc/withDotValue/tsconfig.json Adds a dedicated tsc fixture project for the new coverage.
test-workspace/tsc/withDotValue/helper.ts Adds a plain function binding used to assert call-site type errors are surfaced.
test-workspace/tsc/withDotValue/refHelper.ts Adds a ref(fn) binding to validate callable-ref narrowing in templates.
test-workspace/tsc/withDotValue/main.vue Exercises both event handler and interpolation call sites for plain and ref-wrapped functions.
test-workspace/tsc/tsconfig.json Registers the new fixture in the tsc workspace.
packages/tsc/tests/typecheck.spec.ts Adds expected diagnostics proving the call sites are type-checked.
packages/language-core/types/template-helpers.d.ts Updates __VLS_withDotValue’s assertion type to handle callable refs and non-refs.
packages/language-core/lib/codegen/template/interpolation.ts Detects identifier callees and suppresses .value insertion for calls; records call-accessed bindings.
packages/language-core/lib/codegen/template/context.ts Adds tracking for bindings accessed as call expressions.
packages/language-core/lib/codegen/template/elementEvents.ts Re-asserts __VLS_withDotValue within inline handler closures for called setup bindings.
packages/language-core/lib/codegen/script/template.ts Uses Ref<unknown> in the top-level __VLS_withDotValue calls to avoid any leakage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

`callAccessedBindings` is shared across the whole template, so the previous
before/delta diff skipped re-asserting a binding that was already called in
an earlier handler. Reset the set before each handler so every called
binding gets its own in-closure `withDotValue` assertion.
Extend "called binding → no .value" from a direct identifier callee to the
whole callee subtree: parenthesized, non-null, type-asserted, logical
binary, conditional and tagged-template callees no longer get `.value`.
Property/element-access receivers, call arguments and conditions keep it.
@johnsoncodehk
johnsoncodehk merged commit 7ad4a94 into master Aug 24, 2026
7 checks passed
@johnsoncodehk
johnsoncodehk deleted the fix/with-dot-value-function-call branch August 24, 2026 18:06
johnsoncodehk added a commit that referenced this pull request Aug 27, 2026
The master merge brought #6184 (unwrap setup bindings by value), #6181
(calling template bindings without .value), #6179 (unmapped diagnostics),
and the withDotValue/unwrapBindingAccess fixtures, all of which change the
generated virtual code and the diagnostics the corpus reports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants