since [email protected] type declaration requires ts >= 4.5

This issue has been tracked since 2022-07-15.

It looks like since #1165 landed in the repo, the bundled type declarations use mixed exports (exporting both type and values) which was introduced in TS 4.5 AFAIK.

I am wondering if there's an assumption that the consumer of the package runs a specific version of TS since the [email protected] release line. I tried to use that library in a project that runs under TS 4.2 and the type checker errors out as it doesn't understand the mixed exports syntax. That's the kind of error that are being thrown:

node_modules/htmlparser2/lib/index.d.ts:2:23 - error TS1005: ',' expected.

2 export { Parser, type ParserOptions };
                        ~~~~~~~~~~~~~

Maybe we could add a note about the minimum TS requirement or provide backward compatible type declarations (relying on typesVersion and using a tool such as downlevel-dts).

Thank you so much for your work on this awesome lib and hopefully this is useful feedback

lehui521 wrote this answer on 2022-08-03

I encountered the same problem

fb55 wrote this answer on 2022-08-03

I have added a note to the 8.0.0 release notes: https://github.com/fb55/htmlparser2/releases/tag/v8.0.0

The 7.x releases are still safe to use for users on older TypeScript versions, and I don't see a strong reason to maintain backwards compatibility for old TypeScript releases. Hope that makes sense!

a-liubchenka wrote this answer on 2022-08-03

@fb55 Hi
I spent lots of time today, just due to this problem.
Could you please add perDependencies object in package.json with typescript requirement?
After that I will be notified, that there is a conflict between typescript version requirements. Currently just some magic(
image

fb55 wrote this answer on 2022-08-03

It is possible to use this module without TypeScript. If I added TypeScript as a peer dependency, users that don't use TypeScript would get errors. Unfortunately there is no way to specify optional peer dependencies.

More Details About Repo
Owner Name fb55
Repo Name htmlparser2
Full Name fb55/htmlparser2
Language TypeScript
Created Date 2011-08-27
Updated Date 2023-03-19
Star Count 3793
Watcher Count 50
Fork Count 370
Issue Count 4

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date