hypertag icon indicating copy to clipboard operation
hypertag copied to clipboard

TypeScript support + ESM module error

Open drwpow opened this issue 3 years ago • 3 comments

Hello! First of all, wanted to say that I love this package 💯. It’s so useful having a simple API for finding tags in a string of HTML!

I’m trying to use this in a TypeScript Node project, but there aren’t types. I’d love to add them to this package if you’d be open to it.

But then I also noticed that your module export isn’t working: ReferenceError: module is not defined. There’s a module.exports= line in the ESM code, likely generated from microbundle.

So in that light, would you be open to a PR that converts this project to TypeScript? It’d have the following advantages:

  • It’d offer automatic TS types for people
  • It’d fix the ESM export because TS does a better job
  • It would still generate the same CommonJS bundle for Node
  • We’d keep everything the same, from file structure to core logic to output generation (it wouldn’t impact perf at all). We’d only be adding a couple TS annotations in the code that are simply removed at compile time, so the source and output are the same as before (other than fixing the module export as mentioned).

Let me know if you’re open to this! Would be happy to do the work; just wanted to discuss first.

drwpow avatar Oct 29 '20 18:10 drwpow

Hey @drwpow, thanks for taking the time to open this ticket! My apologies for the long delay, the notification e-mail has slipped through the cracks 😞

I’m totally on board with the change, please feel free to submit your PR.

AndreasPizsa avatar Nov 02 '20 10:11 AndreasPizsa

Awesome. No worries at all 🙂 . Will submit a PR either this week or next

drwpow avatar Nov 02 '20 17:11 drwpow

Hey @drwpow, thanks for the PR! I’ll review it and get back to you.

AndreasPizsa avatar Nov 11 '20 15:11 AndreasPizsa