diff --git a/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts b/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts index 05c32a0c2..9c1f1eeff 100644 --- a/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts +++ b/packages/svelte2tsx/src/svelte2tsx/processInstanceScriptContent.ts @@ -83,7 +83,15 @@ export function processInstanceScriptContent( const jsDocType = ts.getJSDocType(declaration); const type = tsType || jsDocType; - if (!ts.isIdentifier(identifier) || !type) { + if ( + !ts.isIdentifier(identifier) || + (!type && + // Edge case: TS infers `export let bla = false` to type `false`. + // prevent that by adding the any-wrap in this case, too. + ![ts.SyntaxKind.FalseKeyword, ts.SyntaxKind.TrueKeyword].includes( + declaration.initializer?.kind, + )) + ) { return; } const name = identifier.getText(); diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-boolean/expected.tsx b/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-boolean/expected.tsx new file mode 100644 index 000000000..2a7567249 --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-boolean/expected.tsx @@ -0,0 +1,14 @@ +/// +<>;function render() { + + let bla = false;bla = __sveltets_any(bla);; + let blubb = true;blubb = __sveltets_any(blubb);; + let bla1: boolean = false;bla1 = __sveltets_any(bla1);; + let blubb1: boolean = true;blubb1 = __sveltets_any(blubb1);; + let a1 = true;a1 = __sveltets_any(a1);;let a2 = false;a2 = __sveltets_any(a2);;let b1: boolean = true;b1 = __sveltets_any(b1);;let b2: boolean = false;b2 = __sveltets_any(b2);; +; +() => (<>); +return { props: {bla: bla , blubb: blubb , bla1: bla1 , blubb1: blubb1 , a1: a1 , a2: a2 , b1: b1 , b2: b2} as {bla?: typeof bla, blubb?: typeof blubb, bla1?: boolean, blubb1?: boolean, a1?: typeof a1, a2?: typeof a2, b1?: boolean, b2?: boolean}, slots: {}, getters: {}, events: {} }} + +export default class Input__SvelteComponent_ extends createSvelte2TsxComponent(__sveltets_partial(__sveltets_with_any_event(render))) { +} diff --git a/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-boolean/input.svelte b/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-boolean/input.svelte new file mode 100644 index 000000000..34f494ac3 --- /dev/null +++ b/packages/svelte2tsx/test/svelte2tsx/samples/ts-export-boolean/input.svelte @@ -0,0 +1,7 @@ +