-
-
Notifications
You must be signed in to change notification settings - Fork 218
Description
Describe the bug
When using svelte2tsx's emitDts
feature, typically, a component's props' JSDoc comments are included in the emitted .d.ts
file, e.g.
declare const __propDef: {
props: {
/**
* Text content to appear in the button.
*/ text?: string | undefined;
However, if the component contains $$props
, these prop docs disappear.
I believe this is because of the __sveltets_1_with_any
shim, which is rendered by the props
function, if canHaveAnyProp
. Because the prop types are shimmed, we lose the documentation.
Reproduction
Install the SvelteKit template project (using TS syntax), install dependencies, and svelte2tsx
.
npm create svelte@latest my-app
npm i
npm i svelte2tsx
Create a src/lib/MyComponent.svelte
component with a JSDoc-ed prop.
<script lang="ts">
/**
* Foo docs
*/
export let foo = 'bar';
</script>
Run svelte2tsx
's emitDts
function with the following script.
import svelte2tsx from 'svelte2tsx';
import { createRequire } from 'module';
const svelteShimsPath = createRequire(import.meta.url).resolve('svelte2tsx/svelte-shims.d.ts');
svelte2tsx.emitDts({ svelteShimsPath, declarationDir: './dist' })
Inspect dist/src/lib/MyComponent.svelte.d.ts
, note the presence of the prop's JSDoc.
Add $$props
to MyComponent.svelte
.
<script lang="ts">
/**
* Foo docs
*/
export let foo = 'bar';
const a = $$props.a;
</script>
Re-run the above script, inspect dist/src/lib/MyComponent.svelte.d.ts
again. The prop's JSDoc has disappeared.
Expected behaviour
The type file outputted by emitDts
should contain prop JSDoc comments regardless of whether $$props
is present in the component or not.
System Info
- OS: MacOS 11.7
- Node: v17.9.1
Which package is the issue about?
svelte2tsx
Additional Information, eg. Screenshots
No response