Skip to content

Commit 5528888

Browse files
committed
fix
1 parent 0bdd22c commit 5528888

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/parser/converts/attr.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,12 @@ function buildEventHandlerType(
351351
return nativeEventHandlerType;
352352
}
353353
if (element.kind === "component") {
354-
// I think we need to give an expression to the function call in order to reason correctly,
355-
// but that's not currently supported.
356-
// In the first place, the `@typescript-eslint/parser` currently
357-
// cannot correctly parse the import types of `*.svelte`.
358-
// return `(1 as any as ${elementName}['$on'])('${eventName}', $$expr)`;
354+
// `@typescript-eslint/parser` currently cannot parse `*.svelte` import types correctly.
355+
// So if we try to do a correct type parsing, it's argument type will be `any`.
356+
// A workaround is to inject the type directly, as `CustomEvent<any>` is better than `any`.
357+
358+
// const componentEvents = `import('svelte').ComponentEvents<${elementName}>`;
359+
// return `(e:'${eventName}' extends keyof ${componentEvents}?${componentEvents}['${eventName}']:CustomEvent<any>)=>void`;
359360

360361
return `(e:CustomEvent<any>)=>void`;
361362
}
@@ -374,7 +375,7 @@ function buildEventHandlerType(
374375
/* */ /* */ /* */ `'${attrName}' extends infer ATTR`,
375376
/* */ /* */ /* */ `?(`,
376377
/* */ /* */ /* */ /* */ `ATTR extends keyof ${importSvelteHTMLElements}[EVT]`,
377-
/* */ /* */ /* */ /* */ /* */ `?${importSvelteHTMLElements}[U][ATTR]`,
378+
/* */ /* */ /* */ /* */ /* */ `?${importSvelteHTMLElements}[EVT][ATTR]`,
378379
/* */ /* */ /* */ /* */ /* */ `:${nativeEventHandlerType}`,
379380
/* */ /* */ /* */ `)`,
380381
/* */ /* */ /* */ `:${nativeEventHandlerType}`,

0 commit comments

Comments
 (0)