Skip to content

Commit

Permalink
fix: ensure type widening for bind:group
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Apr 1, 2024
1 parent 3ea9c01 commit 66e81f3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ export function handleBinding(
): void {
// bind group on input
if (element instanceof Element && attr.name == 'group' && parent.name == 'input') {
// add reassignment to force TS to widen the type of the declaration (in case it's never reassigned anywhere else)
const expressionStr = str.original.substring(
attr.expression.start,
getEnd(attr.expression)
);
element.appendToStartEnd([
rangeWithTrailingPropertyAccess(str.original, attr.expression),
';'
surroundWithIgnoreComments(`() => ${expressionStr} = __sveltets_2_any(null);`)
]);
return;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///<reference types="svelte" />
;function render() {
async () => { { svelteHTML.createElement("input", { "id":`dom-input`,"type":`radio`,"value":`dom`,});$compile_options.generate;}};
async () => { { svelteHTML.createElement("input", { "id":`dom-input`,"type":`radio`,"value":`dom`,});/*Ωignore_startΩ*/() => $compile_options.generate = __sveltets_2_any(null);/*Ωignore_endΩ*/}};
return { props: /** @type {Record<string, never>} */ ({}), slots: {}, events: {} }}

export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_partial(__sveltets_2_with_any_event(render()))) {
Expand Down

0 comments on commit 66e81f3

Please sign in to comment.