highlightjs / highlight.js

JavaScript syntax highlighter with language auto-detection and zero dependencies.
https://highlightjs.org/
BSD 3-Clause "New" or "Revised" License
23.55k stars 3.58k forks source link

Future: Possibly more automated type compilation #3157

Open joshgoebel opened 3 years ago

joshgoebel commented 3 years ago

Getting access to the types in my main source. My source is all JS, it exports no types... all the type exports are ambient modules.

I’m proposing the inverse: define your types in your code.

I dunno what that means? You mean declare them in highlight.js itself and then export them, import them into index.d.ts and then reexport them? I'm not sure I know how to do that if that's possible - or advisable?

Indeed: write them in JavaScript. No need to add a manual index.d.ts: typescript can compile javascript and generate that index.d.ts.

Here’s a smaller example: https://github.com/words/levenshtein-edit-distance/commit/2c3d890068b0d9405881a94f1439b31f8d08c392. Lowlight is a bit more involved. A bit more complex is unist-util-select: https://github.com/syntax-tree/unist-util-select/commit/4c1b02e34f849394bc90b42ea3bce0f52d9b2512. And quite complex is xdm: https://github.com/wooorm/xdm.

I am not a fan of typescript. I personally don’t really love types either. But they are somewhat useful — especially for newcomers to a giant ecosystem (unified). I think types through jsdoc in javascript is rather nice: code is directly runnable, no building needed. But everything is still type checked by typescript (and I like type-coverage to ensure everything is completely typed). It ensures .d.ts are kept up to date and work

Some more info here: https://github.com/voxpelli/types-in-js

Originally posted by @wooorm in https://github.com/highlightjs/highlight.js/issues/3131#issuecomment-824157692

joshgoebel commented 3 years ago

If someone knows how this is done and would like to whip up a tiny PR, I'd love to see it. I think what would be since is a tiny utility script that we could run periodically that would compile the types. I also wonder if this magically will create ambient modules as we do now.