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

Adding an extra typings declaration file (src/*.d.ts) to be exported? #127

Closed
jnachtigall opened this issue Oct 12, 2022 · 4 comments
Closed

Comments

@jnachtigall
Copy link

I use vite lib mode to create a webcomponent library. For the typings to work in JSX (React) I need an extra d.ts file. The name is not important as long as it is under src with is included by tsconfig.json.

In my case it is src/webcomponent-custom-element.d.ts:

declare namespace JSX {
  interface IntrinsicElements {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    "my-webcomponent": any;
  }
}

(This file is needed otherwise there's an JSX error when I use the custom element with ` in the JSX file.)

Within vite the error is then gone. However, when I build the lib then this file gets copied over to the `dist´. But in the consumer of the lib then there is still the JSX TypeScript error.

I think this is because the package.json has only "types": "./dist/my-lib.d.ts",. So it does not know about the webcomponent typings.

Any idea on how I could get these extra file properly exported?

I saw #55 to use rollupTypes: true but this results in #126.

@qmhc
Copy link
Owner

qmhc commented Oct 13, 2022

Do it work normally with v1.6.6?

@jnachtigall
Copy link
Author

Still not working, see my comment at #126 (comment)

@jnachtigall
Copy link
Author

And it does not get merged into one file, see outputDir

$ ls dist-lib/
mainWebComponent.d.ts  ozgerde-vorgangsportal.js  vite-env.d.ts  vite.svg  webcomponent-custom-element.d.ts

So there are 3 *.d.ts files. I would expect them all to be merged into mainWebComponent.d.ts which is given in the package.json as "types": "./dist-lib/mainWebComponent.d.ts",

@jnachtigall
Copy link
Author

You can reproduce this the repo from #126 (comment)

@qmhc qmhc closed this as completed Nov 14, 2022
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