Skip to content

Commit

Permalink
fix(language-core): fix event handler type for hyphen-case event names
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed May 13, 2024
1 parent 2a3ea17 commit 60352eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/language-core/lib/codegen/template/elementEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export function* generateElementEvents(
yield `/**__VLS_emit,${emitVar},${prop.arg.loc.source}*/${newLine}`;
yield `'${originalPropName}': typeof ${eventsVar}['${prop.arg.loc.source}']${newLine}`;
yield `}${newLine}`;
if (prop.arg.loc.source !== camelize(prop.arg.loc.source)) {
yield `: __VLS_IsAny<typeof ${eventsVar}['${camelize(prop.arg.loc.source)}']> extends false${newLine}`;
yield `? {${newLine}`;
yield `/**__VLS_emit,${emitVar},${camelize(prop.arg.loc.source)}*/${newLine}`;
yield `'${originalPropName}': typeof ${eventsVar}['${camelize(prop.arg.loc.source)}']${newLine}`;
yield `}${newLine}`;
}
yield `: typeof ${propsVar}${newLine}`;
yield `> = {${newLine}`;
yield* generateEventArg(options, ctx, prop.arg, true);
Expand Down
4 changes: 2 additions & 2 deletions test-workspace/tsc/vue3/events/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<C1 @foo-bar="exactType($event, {} as number)" @bar-baz="exactType($event, {} as number)" />
<C2 @foo-bar="exactType($event, {} as number)" />
<C3 @foo-bar="exactType($event, {} as number)" />
<C4 value="1" @foo-bar="exactType($event, {} as any)" />
<C4 :value="1" @foo-bar="exactType($event, {} as any)" />
<C4 value="1" @foo-bar="exactType($event, {} as string)" />
<C4 :value="1" @foo-bar="exactType($event, {} as number)" />

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

0 comments on commit 60352eb

Please sign in to comment.