Skip to content

Commit

Permalink
fix(language-core): type narrowing not working for inline event handler
Browse files Browse the repository at this point in the history
close #4209
  • Loading branch information
johnsoncodehk committed Apr 4, 2024
1 parent c83045c commit 3f2f953
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/language-core/lib/generators/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export function* generate(
blockConditions.push(
toString(
[...generateInterpolation(branch.condition.content, branch.condition.loc, undefined, undefined, '(', ')')]
.map(code => code[1])
.map(([code]) => code)
)
);
addedBlockCondition = true;
Expand Down
32 changes: 32 additions & 0 deletions test-workspace/tsc/vue3/#4209/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<script setup lang="ts">
type Bar = {
id: string;
} | null;
type Example = {
foo: {
bar: Bar;
};
doSomething(id: string): void;
};
const example: Example = {
foo: {
bar: {
id: '123',
},
},
doSomething(id: string) {
console.log(id);
},
};
</script>

<template>
<button
v-if="example.foo.bar"
type="button"
v-on:click="example.doSomething(example.foo.bar.id)"
>
{{ example.foo.bar.id }}
</button>
</template>

0 comments on commit 3f2f953

Please sign in to comment.