Skip to content

Prop JSDoc not emitted for components using $$props #1698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
egargan opened this issue Oct 21, 2022 · 2 comments
Open

Prop JSDoc not emitted for components using $$props #1698

egargan opened this issue Oct 21, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@egargan
Copy link

egargan commented Oct 21, 2022

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

@egargan egargan added the bug Something isn't working label Oct 21, 2022
@dummdidumm
Copy link
Member

Probably the same cause as #1377

@egargan
Copy link
Author

egargan commented Oct 21, 2022

Do you think this is an easy fix? I'm not too familiar with svelte2tsx but it seems like it won't be easy to handle docs when shimming.

I'm considering removing $$props from my components to get around this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants