sveltejs / language-tools

The Svelte Language Server, and official extensions which use it
MIT License
1.26k stars 202 forks source link

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

Open NaviTheCoderboi opened 1 month ago

NaviTheCoderboi commented 1 month ago

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

jasonlyu123 commented 1 month ago

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,

NaviTheCoderboi commented 1 month ago

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

dummdidumm commented 3 weeks ago

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