language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

tsc generating wrong .d.ts for tsx generated by svelte2tsx

Open NaviTheCoderboi opened this issue 1 year ago • 3 comments

guys i am using svelte2tsx for transforming svelte to tsx for gneerating .d.ts

        const tsx = s2x.svelte2tsx(content, {
            filename: file,
            isTsFile: isTsScript(content),
            emitOnTemplateError: false,
            version: svelte.VERSION,
            mode: 'dts'
        });

i get such output

import { SvelteComponentTyped } from "svelte"

;function render() {
;type $$ComponentProps =  {
        name: string;
    };
    const {
        name
    }:/*Ωignore_startΩ*/$$ComponentProps/*Ωignore_endΩ*/ = $props(); 
;
async () => {

 { svelteHTML.createElement("h1", {});
     name;
 }

 { svelteHTML.createElement("h2", {}); }
};
return { props: {} as any as $$ComponentProps, exports: {}, bindings: __sveltets_$$bindings(''), slots: {}, events: {} }}
const Foo = __sveltets_2_fn_component(render());
export default Foo;

when i use typescript on it , i t gives me such .d.ts file, how do i fix it?

declare const Foo: any;
export default Foo;

my code: https://github.com/NaviTheCoderboi/foo

NaviTheCoderboi avatar Oct 26 '24 12:10 NaviTheCoderboi

svelte2tsx also has an emitDts mode you can use. https://github.com/sveltejs/language-tools/blob/master/packages/svelte2tsx/src/emitDts.ts. You can also reference the implementation If you have a specific reason for not using it,

jasonlyu123 avatar Oct 26 '24 13:10 jasonlyu123

@jasonlyu123 i have written my code from that only, but i am not getting expected output

NaviTheCoderboi avatar Oct 26 '24 13:10 NaviTheCoderboi

Please provide a proper reproduction (the link is a 404)

dummdidumm avatar Nov 05 '24 13:11 dummdidumm

Closing because the reproduction is no longer available, and this is most likely due to the shim files not being loaded.

jasonlyu123 avatar Sep 28 '25 05:09 jasonlyu123