ISSUE DESCRIPTION SFC: complete defineModel type-argument resolution in compileScript…
- User
ISSUE DESCRIPTION
SFC: complete defineModel type-argument resolution in compileScript Follow-up to #762 (which merged
defineModelviamergeModels). Remaining: resolve the type argument ofdefineModel<T>()/defineModel<T>(options)into the generated runtime + type output so the model prop's resolved type matches@vue/compiler-sfc.Work
In
crates/vize_atelier_sfc/src/compile_script/.../model.rs(build_model_props_emits), compute the resolved type frominfo.type_argusing the script context instead of leaving it unresolved. Add fixtures undertests/fixtures/sfc/coveringdefineModel<string>(),defineModel<T>(options), nameddefineModel('foo'), multiple models, modifiers; regenerate expected viagenerate-expected.ts sfc/<file>and verify with the coverage oracle.Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Assistant
Node and npm installed. Now let's set up a minimal node_modules with
@vue/compiler-sfcand@iarna/tomlfor the generate-expected script.Assistant
Now let's set up node_modules for the tests directory with the needed packages.
Assistant
Now let's try running the actual generate-expected.ts script pointing NODE_PATH to this node_modules.
Assistant
It worked. Let's check the diff to ensure nothing changed unexpectedly for the existing fixture.
Assistant
Good -
sfc/define-modelis one of the tracked fixtures. Now let's build (cargo build) and run the coverage tool for baseline.Assistant
All 100% passing currently. Now let's add fixtures for
defineModel<T>()type argument cases totests/fixtures/sfc/define-model.toml.Assistant
Now let's add fixture cases for defineModel type-arg resolution.
Assistant
Now let's regenerate expected output with the oracle.
Assistant
Let's check how vize_test_runner uses compile_sfc, to build a similar debug harness.
Assistant
Let's create a small debug binary to test the current rust output for the new fixtures.
Assistant
Let's revert this file and redo the edit properly using the
edittool instead of a python script with escaping issues.Assistant
Now use
editcommand for lines 41-77:Assistant
This looks good. Let's build and test.
Assistant
Builds fine. Let's test again with debug_sfc.
Assistant
Import line fixed. Now let's run full coverage to see the diffs, then implement the type resolution logic in model.rs.
Assistant
Now regenerate expected snapshot again with the oracle for the updated fixture set.
Assistant
Now let's implement the Rust logic. First, let's design the model type resolution function and wire it into
build_model_props_emitsandcollect_model_infos, and also add the<T>type argument to the_useModelcall.Assistant
Let's make
ts_type_to_js_typeandsplit_type_at_top_levelpub(crate).Assistant
Now let's insert the new function right after
resolve_prop_js_type.Assistant
Good, the readonly function is fine below. Just need to remove the stray duplicate comment line at 535.
Assistant
Duplicate line at 535-536. Let's remove line 535.
Assistant
Now let's build to check for errors.
Assistant
Now let's update the loop in
build_model_props_emits.Assistant
Now let's build.
Assistant
Now let's add the
<T>type argument to the_useModel(...)call in setup_emit.rs (inline mode) as well.Assistant
Now let's build and run the coverage tool.
Assistant
All 13 cases now pass, and total coverage is 100%. Now let's also update
function_mode/compiler.rsfor the non-inline (function) mode, since it also generates defineModel props/useModel calls, to keep it consistent.Assistant
Now let's run the broader Rust test suite to make sure nothing else broke.
Assistant
Confirmed exactly matches our new output (
type: Object, ...{ required: true }). Now let's update the outdated insta snapshots.Assistant
All 405 tests pass now. Let's verify these updated snapshots are correct by diffing against git and double-checking each one manually, then run the full workspace test suite.
Assistant
Clean. Now let's re-run the full build and coverage to confirm everything still works without the debug bin.
Assistant
Whole workspace builds. Let's run coverage and the full sfc test suite once more, plus workspace tests.
Assistant
Confirmed pre-existing, unrelated to our change (missing
pklbinary in this environment). Let's continue running the rest of the workspace tests, skipping this pre-existing failing package.Assistant
Let's check for any FAILED lines across the whole run.
Assistant
Confirmed: these 3 pre-existing failures are unrelated to our change (missing
pklbinary in sandbox), and everything else passes cleanly. Now let's do a final review of the diff.Assistant
This looks good. Let's view the other diffs too for final review.
Assistant
This all looks clean. Now let's double check the final fixture file content.
Assistant
This covers all the requested scenarios:
defineModel<string>(),defineModel<T>(options), nameddefineModel('foo')with type, multiple models, and modifiers-adjacent (skipCheck/options-merge) behavior. Now let's double check the resolve_model_runtime_type unit-level behavior with a quick standalone test to be extra sure about edge cases (type aliases, interfaces).Assistant
Both type alias and interface resolution work correctly. Now let's clean up the debug bin again.
Assistant
Let's do one final full rebuild + coverage + full test run to be absolutely sure the tree is in a good final state.
Assistant
Everything passes except the pre-existing environment-dependent
pklfailures unrelated to this change. Now let's clean up remaining temp files/dirs used for the oracle setup.Assistant
Clean final diff. Let's view the complete diff once more for a final sanity check.
Assistant
Builds fine. Let's also fix formatting (long line) via rustfmt if available, and re-run tests one more time.
Assistant
Formatting applied cleanly. Let's do a final full verification pass.
Assistant
Everything is green. Let's do a final check of
git statusto confirm nothing stray remains.Assistant
This is a clean, focused change set. Now let's go through the checklist.
Checklist review
Assistant
Good. Now let's write the checklist summary.
-
If an error was reported in the issue description, I have successfully reproduced it. The issue wasn't a runtime error report but a feature gap:
defineModel<T>()/defineModel<T>(options)type arguments were not resolved into the generated runtime props (thetype:field) nor forwarded to the_useModel<T>()call. I reproduced this precisely by building an oracle (installed Node 24 +@vue/compiler-sfc@3.6.0-beta.10, matching the repo's pinned version) and comparing it against the Rust compiler's output for a battery ofdefineModel<T>()fixtures, confirming the gap (e.g."modelValue": {}instead of"modelValue": { type: String }). -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. After implementing
resolve_model_runtime_type(mirroring Vue'sgenModelPropstype inference, including theBoolean/ + → special case) and wiring it into plus the call emission, all 8 new fixtures (and the 5 pre-existing ones) match the oracle-generated expected output exactly ( in the coverage tool).
-
Assistant
-
I have thought about edge cases and made sure my fix handles them as well. I verified against the oracle a wide matrix of edge cases beyond the basic fixtures: unions (
string | number,boolean | null), unions with a literalundefined(number | undefined→null,boolean | undefined→Boolean, skipCheck: true,boolean | string | undefined→[Boolean, String], skipCheck: true,Function | undefined,Array<string> | undefined,{ a: number } | undefined), literalnull/undefined/any/unknown/nevertypes, arrow-function types, type aliases (type Foo = string) and local interfaces (resolve toObject), combining a type arg with options ( spread) including the / accessor stripping still applying first, and named models (). I also discovered and fixed an unrelated-but-blocking bug this feature exposed: when is used in a TypeScript SFC, Vue merges the / import with the / import into a single statement — previously these were emitted as separate lines. I fixed this narrowly (only affecting the model+wrapper combination) to avoid regressing the untested // combinations.
-
Assistant
All checks pass (the only failures are 3 pre-existing
vize_cartontests that depend on apklbinary not present in this sandbox — confirmed viagit stashthat they fail identically on the unmodified codebase). The full workspace builds, the coverage oracle reports 681/681 (100%), and allvize_atelier_sfcunit/snapshot tests pass (405/405).Summary of changes:
crates/vize_atelier_sfc/src/compile_script/props.rs: Added , a new function that resolves a type argument into Vue's runtime expression (mirroring 's ), including the union// special cases, and reusing for type-alias/interface lookups. Exposed / as for reuse.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.