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] private ComponentType interface breaks type declarations #14256

Closed
Theo-Steiner opened this issue Nov 11, 2024 · 4 comments
Closed

[bug] private ComponentType interface breaks type declarations #14256

Theo-Steiner opened this issue Nov 11, 2024 · 4 comments

Comments

@Theo-Steiner
Copy link
Contributor

Describe the bug

When using tsc to emit types for a svelte 5 project with "declarations": true set in the tsconfig.json, the compilation fails with an error: error TS4082: Default export of the module has or is using private name 'ComponentType'.

(Interestingly, the problem only seems to occur, when a component is passed "through" a generic function, in case of the reproduction: doSth)

Reproduction

https://stackblitz.com/edit/vitejs-vite-fgmgkx?file=src%2Findex.ts

run npx tsc to see how the compilation fails.

Potential fix:
if we go to node_modules/svelte/types/index.d.ts line 2315 however, and modify it to export the interface, the compilation finishes without error.

Logs

No response

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 88.94 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.12.0 - ~/Library/Caches/fnm_multishells/75820_1731292463955/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 8.19.2 - ~/Library/Caches/fnm_multishells/75820_1731292463955/bin/npm
  Browsers:
    Chrome: 106.0.5249.91
    Safari: 17.5
  npmPackages:
    svelte: ^5.1.9 => 5.1.12

Severity

blocking an upgrade

@dummdidumm
Copy link
Member

What is the reason for using tsc to emit types, instead of svelte-package?

@Theo-Steiner
Copy link
Contributor Author

What is the reason for using tsc to emit types, instead of svelte-package?

This is for a library of web components, so svelte has to be compiled to JavaScript in the build step.
This was (is) not trivial to build with svelte-package.
For this reason we use a custom pipeline when building, that includes emitting types via tsc

@dummdidumm
Copy link
Member

I'm wondering if that is of much use, since TS doesn't know anything about the shape of the components - is that a non-problem in your case?

@Theo-Steiner
Copy link
Contributor Author

Yeah, that's a non-problem in our case.
The user will just register a custom element via a side effect from importing the entrypoint (that's what doSth from the reproduction does in our case).
But internally we make use of the component type returned from doSth to type the props of a custom render function used for testing.
I realize this is not a common use case, but I still don't think returning a generic component type should break typescript

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

No branches or pull requests

2 participants