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

Enums raise error in @h5web/app declaration types #1099

Closed
loichuder opened this issue May 4, 2022 · 1 comment · Fixed by #1132
Closed

Enums raise error in @h5web/app declaration types #1099

loichuder opened this issue May 4, 2022 · 1 comment · Fixed by #1132
Assignees

Comments

@loichuder
Copy link
Member

Describe the bug

The built declaration types of @h5web/app give the following error at the first encountered enum:

Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier.ts(1046)

To Reproduce

  1. Go in packages/app
  2. Run pnpm build:dts
  3. Open dist/index.d.ts
  4. See error ts(1046)

Context

Encountered when trying to build jupyterlab-h5web with h5web@4.1.0

Additional info

@axelboc
Copy link
Contributor

axelboc commented May 4, 2022

Hmm, I think it's a consequence of the way the @h5web/shared package is set up, more precisely the fact that it is not marked as an "external" dependency during the build (if you recall, we have to bundle it inside the other packages since it's not published to NPM).

In @h5web/shared, we have a step to build the types to dist-ts with tsc, but I have a feeling that these built types are in fact not used.

When we run tsc in the other packages, @h5web/shared imports are left as is, because TS considers them external imports. We then run Rollup to merge the dist-ts types into a single file, but since @h5web/shared is not marked as external (contrary to @h5web/lib for instance), Rollup tries to find its types to bundle them, but it can't find them because shared/package.json doesn't have a types field (otherwise we'd have to continuously rebuild the types in development). So Rollup (or rather rollup-plugin-dts) tries to read the types from the source files and it looks like it's pretty bad at doing that.

I reckon the Rollup plugin just copies over anything that is imported with import type. In lib/dist/index.d.ts, you can see for instance that the entire mockValues object is bundled in as is. I think this is due to the type import in shared/src/mock/models.ts. Similarly, we use a type import for EntityKind somewhere in the app package.

I'm not seeing a quick and easy solution for this issue right now, unfortunately, but at least I understand why it's happening, which is a good step. 😄 I'll keep thinking.

@axelboc axelboc self-assigned this May 4, 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

Successfully merging a pull request may close this issue.

2 participants