Skip to content
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

[BUG] IntelliSense fails with imported types using $props() - Svelte 5 #2549

Open
roonie007 opened this issue Oct 28, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@roonie007
Copy link

roonie007 commented Oct 28, 2024

Describe the bug

I've been experiencing a problem with IntelliSense when using Svelte's $props ( same problem on VS Code and Webstorm ).

When I import a type from @nextui-org/theme and use it as the props type for my component's attributes, IntelliSense doesn't work at all:

<script lang="ts">
import type { ButtonVariantProps } from '@nextui-org/theme';

const someProps: ButtonVariantProps = $props();
</script>

image


If I extend it with a Snippet, for example, I only get the children prop:

<script lang="ts">
import type { ButtonVariantProps } from '@nextui-org/theme';
import type { Snippet } from 'svelte';

interface Props extends ButtonVariantProps {
  children?: Snippet;
}

const someProps: Props = $props();
</script>

image

But when I start typing something for example is and press CTRL+Space to trigger the intellisense, it actually show the intellisense with words that contains is
image


However, if I just use one of its field types, it works:

<script lang="ts">
import type { ButtonVariantProps } from '@nextui-org/theme';
import type { Snippet } from 'svelte';

interface Props {
  children?: Snippet;
  fullWidth?: ButtonVariantProps['fullWidth'];
}

const someProps: Props = $props();
</script>

image


I thought it might be a TypeScript issue, so I tried the non-working code in a simple TypeScript file, and everything works as expected:

image

The fact that it's the same problem in VSCode and Webstorm, and it works with a simple typescript file, this leads me to believe the problem is specific to Svelte

Reproduction

install the @nextui-org/theme module and create a component with the following code:

<script lang="ts">
import type { ButtonVariantProps } from '@nextui-org/theme';

const someProps: ButtonVariantProps = $props();
</script>

Now try checking the attributes intelliSense when you use the component

Expected behaviour

When using the component, IntelliSense should provide autocompletion and type suggestions based on the ButtonVariantProps type imported from @nextui-org/theme. All properties defined within ButtonVariantProps should be available in IntelliSense to enhance the development experience.

System Info

  System:
    OS: Linux 5.15 Ubuntu 24.04.1 LTS 24.04.1 LTS (Noble Numbat)
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i5-12600K
    Memory: 23.47 GB / 27.30 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  Binaries:
    Node: 22.9.0 - ~/.nvm/versions/node/v22.9.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v22.9.0/bin/yarn
    npm: 10.8.3 - ~/.nvm/versions/node/v22.9.0/bin/npm
    bun: 1.1.33 - ~/.bun/bin/bun

Which package is the issue about?

No response

Additional Information, eg. Screenshots

svelte: 5.0.0
typescript: 5.6.3
vite: 5.0.3
@roonie007 roonie007 added the bug Something isn't working label Oct 28, 2024
@garug
Copy link

garug commented Oct 29, 2024

Very good doc, I noted $props works well on routing svelte components like +page.svelte but on isolated components on $lib no

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