Skip to content

Commit 60352eb

Browse files
committed
fix(language-core): fix event handler type for hyphen-case event names
1 parent 2a3ea17 commit 60352eb

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/language-core/lib/codegen/template/elementEvents.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ export function* generateElementEvents(
4646
yield `/**__VLS_emit,${emitVar},${prop.arg.loc.source}*/${newLine}`;
4747
yield `'${originalPropName}': typeof ${eventsVar}['${prop.arg.loc.source}']${newLine}`;
4848
yield `}${newLine}`;
49+
if (prop.arg.loc.source !== camelize(prop.arg.loc.source)) {
50+
yield `: __VLS_IsAny<typeof ${eventsVar}['${camelize(prop.arg.loc.source)}']> extends false${newLine}`;
51+
yield `? {${newLine}`;
52+
yield `/**__VLS_emit,${emitVar},${camelize(prop.arg.loc.source)}*/${newLine}`;
53+
yield `'${originalPropName}': typeof ${eventsVar}['${camelize(prop.arg.loc.source)}']${newLine}`;
54+
yield `}${newLine}`;
55+
}
4956
yield `: typeof ${propsVar}${newLine}`;
5057
yield `> = {${newLine}`;
5158
yield* generateEventArg(options, ctx, prop.arg, true);

test-workspace/tsc/vue3/events/main.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<C1 @foo-bar="exactType($event, {} as number)" @bar-baz="exactType($event, {} as number)" />
88
<C2 @foo-bar="exactType($event, {} as number)" />
99
<C3 @foo-bar="exactType($event, {} as number)" />
10-
<C4 value="1" @foo-bar="exactType($event, {} as any)" />
11-
<C4 :value="1" @foo-bar="exactType($event, {} as any)" />
10+
<C4 value="1" @foo-bar="exactType($event, {} as string)" />
11+
<C4 :value="1" @foo-bar="exactType($event, {} as number)" />
1212

1313
<C1 @fooBar="exactType($event, {} as number)" @barBaz="exactType($event, {} as any)" />
1414
<C2 @fooBar="exactType($event, {} as number)" />

0 commit comments

Comments
 (0)