highlight.js: Typescript cannot locate the type information of the core module.
Hi there π
Iβd like to import the core and only necessary language files. I tried as below but then realised that there is something wrong in package regarding typings.
import hljs from 'highlight.js/lib/core'
import javascript from 'highlight.js/lib/languages/javascript'
Could not find a declaration file for module 'highlight.js/lib/core'.
I have not imported the index module i.e. import hljs from 'highlight.js. So, typescript canβt locate the type information for the core module from a subfolder. I believe the solution might be creating .d.ts file for every subfolder and file in your case.
I quickly fixed this issue locally by creating a core.d.ts file under lib directory. So, I guess we need to declare the entire API that the library exposes.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 37 (24 by maintainers)
FYI setting reference seems to play nice as near as I can tell.
In my case the file importing core is in src/filename.ts
From there register your languages:
@joshgoebel When I ran
cp -r /tmp/highlight.js/build ./node_modules/highlight.js, it workedAnd index.d.ts can still live in the
typesfolder with a reference in package.jsontypesthen?