Skip to content

Commit

Permalink
fix(language-core): generate defineModel emits type on-demand (#4052)
Browse files Browse the repository at this point in the history
  • Loading branch information
so1ve authored Mar 20, 2024
1 parent 618a42c commit 02af955
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/language-core/lib/generators/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -872,12 +872,14 @@ type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
}
yield _(`},\n`);
}
yield _(`emits: ({} as __VLS_NormalizeEmits<typeof __VLS_modelEmitsType`);
if (ranges.emits.define) {
yield _(` & typeof `);
yield _(ranges.emits.name ?? '__VLS_emit');
if (ranges.defineProp.filter(p => p.isModel).length || ranges.emits.define) {
yield _(`emits: ({} as __VLS_NormalizeEmits<typeof __VLS_modelEmitsType`);
if (ranges.emits.define) {
yield _(` & typeof `);
yield _(ranges.emits.name ?? '__VLS_emit');
}
yield _(`>),\n`);
}
yield _(`>),\n`);
}
if (script && scriptRanges?.exportDefault?.args) {
yield _(generateSourceCode(script, scriptRanges.exportDefault.args.start + 1, scriptRanges.exportDefault.args.end - 1));
Expand Down
9 changes: 9 additions & 0 deletions test-workspace/tsc/vue3/#4050/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup lang="ts"></script>

<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
emits: ['hasFart'],
});
</script>

0 comments on commit 02af955

Please sign in to comment.