Skip to content

Commit 66e81f3

Browse files
committed
fix: ensure type widening for bind:group
#2316
1 parent 3ea9c01 commit 66e81f3

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

packages/svelte2tsx/src/htmlxtojsx_v2/nodes/Binding.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@ export function handleBinding(
5959
): void {
6060
// bind group on input
6161
if (element instanceof Element && attr.name == 'group' && parent.name == 'input') {
62+
// add reassignment to force TS to widen the type of the declaration (in case it's never reassigned anywhere else)
63+
const expressionStr = str.original.substring(
64+
attr.expression.start,
65+
getEnd(attr.expression)
66+
);
6267
element.appendToStartEnd([
63-
rangeWithTrailingPropertyAccess(str.original, attr.expression),
64-
';'
68+
surroundWithIgnoreComments(`() => ${expressionStr} = __sveltets_2_any(null);`)
6569
]);
6670
return;
6771
}

packages/svelte2tsx/test/htmlx2jsx/samples/binding-group-bare/expectedv2.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/svelte2tsx/test/htmlx2jsx/samples/binding-group/expectedv2.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/svelte2tsx/test/htmlx2jsx/samples/editing-binding/expectedv2.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/svelte2tsx/test/svelte2tsx/samples/binding-group-store/expectedv2.ts

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

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

0 commit comments

Comments
 (0)