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

@next does not compile with tsconfig option "noUnusedLocals": true #1607

Open
fnimick opened this issue Jan 9, 2025 · 2 comments
Open

@next does not compile with tsconfig option "noUnusedLocals": true #1607

fnimick opened this issue Jan 9, 2025 · 2 comments

Comments

@fnimick
Copy link
Contributor

fnimick commented Jan 9, 2025

Describe the bug

The current components use the old generic implementation, which requires explicit declaration of generic types in a module script prior to their usage in the component. As an example, in form-field.svelte:

<script lang="ts" module>
	import type { FormPath as _FormPath } from "sveltekit-superforms";
	type T = Record<string, unknown>;
	type U = _FormPath<T>;
</script>

<script lang="ts" generics="T extends Record<string, unknown>, U extends _FormPath<T>">
	import * as FormPrimitive from "formsnap";
...

As of svelte 5, the entire module block is no longer required for generics to function, and Typescript currently errors with

Error: 'U' is declared but never used. (ts)
	type T = Record<string, unknown>;
	type U = _FormPath<T>;
</script>

Svelte generics docs: https://svelte.dev/docs/svelte/typescript#Generic-$props

Reproduction

no reproduction - compiler error is in shadcn source

Logs

No response

System Info

System:
    OS: macOS 15.2
    CPU: (10) arm64 Apple M1 Pro
    Memory: 137.55 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.13.1 - ~/.asdf/installs/nodejs/20.13.1/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 10.5.2 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 9.7.0 - ~/.asdf/shims/pnpm
  Browsers:
    Chrome: 131.0.6778.205
    Safari: 18.2
  npmPackages:
    @sveltejs/kit: ^2.5.27 => 2.15.1 
    bits-ui: ^1.0.0-next.77 => 1.0.0-next.77 
    formsnap: ^2.0.0 => 2.0.0 
    lucide-svelte: ^0.469.0 => 0.469.0 
    mode-watcher: ^0.5.0 => 0.5.0 
    svelte: ^5.0.0 => 5.16.2 
    svelte-sonner: ^0.3.28 => 0.3.28 
    sveltekit-superforms: ^2.22.1 => 2.22.1

Severity

annoyance

@huntabyte
Copy link
Owner

To my knowledge that is not the old generics and is the current way to implement generics even in Svelte 5.

The issue is that Svelte doesn't create those types / the eslint plugin doesn't text them so we need to declare them or things go sour.

Perhaps this is an issue to open with either the Svelte eslint plugin or svelte language tools?

@fnimick
Copy link
Contributor Author

fnimick commented Jan 16, 2025

Based on the current documentation: https://svelte.dev/docs/svelte/typescript#Generic-$props - it appears that the module script is no longer necessary? Or at least, having the previously required module block is no longer mentioned anywhere in the documentation.

For the shadcn components I tested, if you delete the module block entirely, everything works as expected. There are no errors about missing types when the module block is removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants