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

svelte-package does not take into account exports entry points #13456

Open
x0k opened this issue Feb 12, 2025 · 2 comments
Open

svelte-package does not take into account exports entry points #13456

x0k opened this issue Feb 12, 2025 · 2 comments
Labels
pkg:svelte-package Issues related to svelte-package

Comments

@x0k
Copy link

x0k commented Feb 12, 2025

Describe the bug

I have a base package which exports ComponentProps interface.
This package also have a subpath export ./extension which extends ComponentProps via module augmentation and interfaces merging.

export interface WidgetProps<V> {
  value: V
}

declare module './index.js' {
  interface ComponentProps {
    text: WidgetProps<string>
  }
}

In another package impl i use augmented ComponentProps type to define properties type for the text-widget.svelte component.

  const { value }: ComponentProps["text"] = $props();

After building the packages the impl/dist/text-widget.svelte.d.ts file contains a definition of TextWidget with type any as props.

declare const TextWidget: import("svelte").Component<any, {}, "">;

Expected

TextWidget must be defined with the correct props type, possibly with import('base/extension').WidgetProps<string> type.

Reproduction

https://github.com/x0k/svelte-props-type-inlining-issue

Run npm i && npm run build -ws to build packages

Logs

System Info

System:
    OS: Linux 6.6 cpe:/o:nixos:nixos:24.11 24.11 (Vicuna)
    CPU: (12) x64 Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz
    Memory: 5.88 GB / 15.56 GB
    Container: Yes
    Shell: 5.2.37 - /run/current-system/sw/bin/bash
  Binaries:
    Node: 22.10.0 - /nix/store/hnkyz55vndmvwhg6nzpliv86gh6sxg7h-nodejs-22.10.0/bin/node
    npm: 10.9.0 - /nix/store/hnkyz55vndmvwhg6nzpliv86gh6sxg7h-nodejs-22.10.0/bin/npm
    pnpm: 9.15.3 - /nix/store/by7hqplbckljzzsq6jpmcjp1w4jzvxpg-pnpm-9.15.3/bin/pnpm
  Browsers:
    Brave Browser: 132.1.74.51
  npmPackages:
    @sveltejs/package: catalog: => 2.3.10 
    @sveltejs/vite-plugin-svelte: catalog: => 5.0.3 
    svelte: catalog: => 5.19.7 
    vite: catalog: => 6.0.11

Severity

annoyance

Additional Information

My original project had a slightly different problem: svelte-package could correctly identify the type of the props, but was inserting the wrong path to the type defined in the subpath entrypoint.

I've been getting this type

declare const TextWidget: import("svelte").Component<import("base/dist/extension").WidgetProps<...

instead of

declare const TextWidget: import("svelte").Component<import("base/extension").WidgetProps<...
@eltigerchino eltigerchino added the pkg:svelte-package Issues related to svelte-package label Feb 13, 2025
@x0k
Copy link
Author

x0k commented Feb 16, 2025

The problem I have been able to reproduce is not related to exports. I recently tried to work around this problem and extracted the extension into a separate package, but the props type is still missing (any).
So I think the main cause of this problem is the module augmentation + interfaces merging.

@x0k
Copy link
Author

x0k commented Feb 20, 2025

I made a mistake in the previous comment, after extracting the code into separate packages I was still using the exports functionality

  "exports": {
    ".": {
      "types": "./dist/export.d.ts",
      "svelte": "./dist/export.js"
    },

So yes, the main problem is with exports.

While debugging, I found that svelte2tsx uses the NodeJs module resolution strategy (code) while the typescript SvelteKit project is generated with the NodeNext strategy by default. Patching this parameter in svelte2tsx package also solves the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:svelte-package Issues related to svelte-package
Projects
None yet
Development

No branches or pull requests

2 participants