diff --git a/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Binding.ts b/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Binding.ts
index b4c6add56..7f7f9dd3e 100644
--- a/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Binding.ts
+++ b/packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Binding.ts
@@ -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;
}
diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/binding-group-bare/expectedv2.js b/packages/svelte2tsx/test/htmlx2jsx/samples/binding-group-bare/expectedv2.js
index 6661e2705..ada26a755 100644
--- a/packages/svelte2tsx/test/htmlx2jsx/samples/binding-group-bare/expectedv2.js
+++ b/packages/svelte2tsx/test/htmlx2jsx/samples/binding-group-bare/expectedv2.js
@@ -1,2 +1,2 @@
- { svelteHTML.createElement("input", { "type":`radio`,"value":`Plain`,});group;}
- { svelteHTML.createElement("input", { "type":`radio`,"value":`Plain`,});group;}
\ No newline at end of file
+ { svelteHTML.createElement("input", { "type":`radio`,"value":`Plain`,});/*Ωignore_startΩ*/() => group = __sveltets_2_any(null);/*Ωignore_endΩ*/}
+ { svelteHTML.createElement("input", { "type":`radio`,"value":`Plain`,});/*Ωignore_startΩ*/() => group = __sveltets_2_any(null);/*Ωignore_endΩ*/}
\ No newline at end of file
diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/binding-group/expectedv2.js b/packages/svelte2tsx/test/htmlx2jsx/samples/binding-group/expectedv2.js
index 3f0525443..e4b496cfb 100644
--- a/packages/svelte2tsx/test/htmlx2jsx/samples/binding-group/expectedv2.js
+++ b/packages/svelte2tsx/test/htmlx2jsx/samples/binding-group/expectedv2.js
@@ -1 +1 @@
- { svelteHTML.createElement("input", { "type":`radio`,"value":`Plain`,});tortilla;}
\ No newline at end of file
+ { svelteHTML.createElement("input", { "type":`radio`,"value":`Plain`,});/*Ωignore_startΩ*/() => tortilla = __sveltets_2_any(null);/*Ωignore_endΩ*/}
\ No newline at end of file
diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/editing-binding/expectedv2.js b/packages/svelte2tsx/test/htmlx2jsx/samples/editing-binding/expectedv2.js
index 84c329d67..196a5d4ba 100644
--- a/packages/svelte2tsx/test/htmlx2jsx/samples/editing-binding/expectedv2.js
+++ b/packages/svelte2tsx/test/htmlx2jsx/samples/editing-binding/expectedv2.js
@@ -1,3 +1,3 @@
- { svelteHTML.createElement("input", { });obj.;}
+ { svelteHTML.createElement("input", { });/*Ωignore_startΩ*/() => obj = __sveltets_2_any(null);/*Ωignore_endΩ*/}
{ svelteHTML.createElement("input", { "bind:value":obj.,});/*Ωignore_startΩ*/() => obj = __sveltets_2_any(null);/*Ωignore_endΩ*/}
{ const $$_tupnI0C = __sveltets_2_ensureComponent(Input); new $$_tupnI0C({ target: __sveltets_2_any(), props: { value:obj.,}});/*Ωignore_startΩ*/() => obj = __sveltets_2_any(null);/*Ωignore_endΩ*/}
\ No newline at end of file
diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/binding-group-store/expectedv2.ts b/packages/svelte2tsx/test/svelte2tsx/samples/binding-group-store/expectedv2.ts
index d8e1d4ea5..efbe52b6a 100644
--- a/packages/svelte2tsx/test/svelte2tsx/samples/binding-group-store/expectedv2.ts
+++ b/packages/svelte2tsx/test/svelte2tsx/samples/binding-group-store/expectedv2.ts
@@ -1,6 +1,6 @@
///
;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} */ ({}), slots: {}, events: {} }}
export default class Input__SvelteComponent_ extends __sveltets_2_createSvelte2TsxComponent(__sveltets_2_partial(__sveltets_2_with_any_event(render()))) {