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
How can I use use highlight.js in TS without all the languages? #2340
Comments
The readme answers this and has an example also: https://github.com/highlightjs/highlight.js#commonjs Require whichever languages you need individially, then register them. Just look at the |
@yyyc514 that is exactly what I stated in my question. |
Sorry for any confusion.
I think you're asking a Typescript specific question. I'm having trouble understanding. Where is it that we have (or provide) types for the library itself if you require the whole thing? Our NPM package is just a bunch of JS files we build. So I'm not sure why you have types for one thing but not others. Someone more familiar with TS might have to jump in here or you might have to make some suggestions on how we might go about even fixing this - since right now I haven no idea. |
This is definitely a TS specific question, maybe I could have pointed to the source of the types. |
Feels like perhaps this issue should be filed/asked against the DefinitelyTyped repo, perhaps? We don't provide typescript types with our npm distro. |
Hi! Agreed. This feels like two questions:
FWIW, https://www.typescriptlang.org/docs/handbook/modules.html#ambient-modules (or if that's not clear, https://stackoverflow.com/questions/44058101/typescript-declare-third-party-modules) might be helpful for both. |
Thanks for the help here I opened an issue in DefinitelyTypedto follow with the discussion. |
Facing some issues with this library as the current documentation (CommonJS section), states that we should import the core file instead of the default import.
However, trying to do on my Angular 9
|
Please see the stable documentation: https://github.com/highlightjs/highlight.js/tree/9-18-stable OR use the v10 beta: |
@yyyc514 I didn't know there was a different npm package for the v10 but glad to see your quick response 👍 The current readme points to the old npm package. |
Yeah, there is an open PR to change the readme to add the new package location. I just published the beta to it's new location today and we're still trying to sort out the proper transition. I think now that we've published it to both places we may have made things more difficult, but I've reached out to NPM support for help to see about the best path forward. |
CC @nikeee, @sourrust and @JoshuaKGoldberg Could any of you help? I'd like to move the type definitions into our repository (so we keep them up-to-date as the library changes, but I'm having a heck of a time figuring out how to do this or if it's even possible). Could any of you look at: |
A workaround for anyone want to use TS with the core import: import hljs from "highlight.js";
declare module "highlight.js/lib/core" {
export = hljs;
} @joshgoebel I think we can also put this into the type definition :D Update: wait you already have that in the definition file.. why it doesn't work I don't know Update 2: Oh it turns out you need to put the "d.ts" in @types/lib/core too https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html#library-file-layout Update 3: ok I managed to get this to work (this is for highlight.js maintainer, while normal users can just use the workaround above in the mean time) Please see both the content and the path to that file |
I read in the README about importing
import * as hljs from 'highlight.js/lib/highlight.js';
instead of the index but this does not have types. Anyone know how I can get types for the file instead of the module?The text was updated successfully, but these errors were encountered: