SFC: complete defineModel type-argument resolution in compileScript Follow-up to #762…
- User
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.
- Assistant
I'll explore the codebase to see how
defineModeltype-argument resolution works today and whatbuild_model_props_emitsstill leaves unresolved. - Assistant
Implementing type-argument resolution and adding fixtures. Checking whether dependencies are available:
- Assistant
Implementing type inference in
props.rsand updatingmodel.rs. - Assistant
Adding fixture cases and updating the snapshot. Checking current compile output:
- Assistant
Fixing output formatting and adding runtime type ordering to match Vue.
- Assistant
All coverage tests pass. Updating the insta snapshot and adding unit tests.
- Assistant
Implemented
defineModeltype-argument resolution inbuild_model_props_emits, matching@vue/compiler-sfc'sgenModelPropsbehavior.Implementation
props.rs— addedinfer_model_runtime_type():- Resolves type aliases/interfaces from the script context
- Maps TS types to runtime constructors via existing
ts_type_to_js_type/resolve_prop_js_type - Applies Vue's unknown-type policy (
skipCheck,type: nullfor generics likeT) - Canonicalizes union order (
[Boolean, String])
model.rs— updatedbuild_model_props_emits():- Reads
type_argsfrom eachdefineModelcall - Resolves via
resolve_type_args()using script context interfaces/aliases - Merges inferred
typewith runtime options:- TS:
{ type: Number, ...{ required: false } } - JS:
Object.assign({ type: Number }, { required: false })
- TS:
Fixtures
Added 6 cases to
tests/fixtures/sfc/define-model.toml:defineModel<string>()defineModel<number>('disabled', { required: false })(type + options)defineModel<string | boolean>()(union)defineModel('title')(named, no type arg)- Multiple typed models
defineModel<T>()withgeneric="T"
Updated
tests/expected/sfc/define-model.snapand raised coverage minimums (SFC: 153, total: 679).Verification
cargo run -p vize_test_runner --bin coverage → 679/679 (100.0%) cargo test -p vize_atelier_sfc model_runtime_type → 4 passedgenerate-expected.tswasn't run here (no Node in the environment); expected output was aligned with Vue'sdefineModel.spec.tspatterns and verified via the coverage oracle.defineModeltype-argument resolution is done.defineModel<T>()calls now resolve their type argument through the script context and emit runtimetypemetadata on model props (e.g.{ type: String },{ type: [Boolean, String] },{ type: Number, ...{ required: false } }), aligned with@vue/compiler-sfc'sgenModelProps.Six new fixtures were added under
tests/fixtures/sfc/define-model.toml, and the coverage oracle passes 679/679.If you have Node available locally, worth running
node tests/tooling/support/generate-expected.ts sfc/define-modelto double-check expected output against Vue's official compiler.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →