Repository navigation
fix(language-core): support calling template bindings without .value - #6181
Merged
Merged
Conversation
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.
There was a problem hiding this comment.
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
.valuewhen a setup binding is the callee of aCallExpression, 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
withDotValuetsc fixture and expected diagnostics to ensure calls are type-checked in both@clickhandlers 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Template expressions that reference a setup binding (a "maybe ref" — could be a
refor a plain value) used to always append.valueand lean on__VLS_withDotValueto justify it. That assertion is a no-op for function declarations:asserts t is fn & { value: fn }does not add.valueto a function, so a function binding becamefn.value(...)→ TS2339 on an unmapped region → silently dropped, and the call was never type-checked.Solution
generateInterpolationnow 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`)..value.__VLS_withDotValuenarrows three cases:T & { value: T }TT & V(callable){} as Ref→{} as Ref<unknown>so the second argument'svalue: anyno longer leaks into the narrowing of union refs.Tests
test-workspace/tsc/withDotValuecovers@click/{{ }}with a plain function and aref(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.valuetobar, andwithDotValuecannot add.valueto 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+withDotValueonly where narrowing (v-if) or assignment (v-model) is required.