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

TypeScript errors when importing package #8

Closed
dank074 opened this issue Sep 10, 2023 · 3 comments · Fixed by #9 or #10
Closed

TypeScript errors when importing package #8

dank074 opened this issue Sep 10, 2023 · 3 comments · Fixed by #9 or #10

Comments

@dank074
Copy link
Contributor

dank074 commented Sep 10, 2023

When I attempt to import the package into my TypeScript project using

import { parseXmltv } from "@iptv/xmltv"

I get the following error:

Could not find a declaration file for module '@iptv/xmltv'. 'c:/Users/***/Documents/my-application/node_modules/@iptv/xmltv/dist/xmltv.js' implicitly has an 'any' type.
  There are types at 'c:/Users/***/Documents/my-application/node_modules/@iptv/xmltv/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@iptv/xmltv' library may need to update its package.json or typings.ts(7016)

I found this in the TypeScript documentation while searching for a solution:

It’s important to note that the CommonJS entrypoint and the ES module entrypoint each needs its own declaration file, even if the contents are the same between them. Every declaration file is interpreted either as a CommonJS module or as an ES module, based on its file extension and the "type" field of the package.json, and this detected module kind must match the module kind that Node will detect for the corresponding JavaScript file for type checking to be correct. Attempting to use a single .d.ts file to type both an ES module entrypoint and a CommonJS entrypoint will cause TypeScript to think only one of those entrypoints exists, causing compiler errors for users of the package
(https://www.typescriptlang.org/docs/handbook/esm-node.html)

evoactivity added a commit that referenced this issue Sep 10, 2023
fix #8: update package.json exports
@evoactivity evoactivity reopened this Sep 10, 2023
@evoactivity
Copy link
Collaborator

Keeping this open until qmhc/vite-plugin-dts#267 is fixed and we can generate the two different files.

@evoactivity
Copy link
Collaborator

evoactivity commented Nov 2, 2023

Someones posted a nice workaround I can use, so I should be able to get the types fully passing on https://arethetypeswrong.github.io/?p=%40iptv%2Fxmltv%400.1.6.

@evoactivity
Copy link
Collaborator

Types are now fully correct according to https://arethetypeswrong.github.io/?p=%40iptv%2Fxmltv%401.0.1 so I am closing this issue.

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