Skip to content

Commit 8e61102

Browse files
authored
fix(types): separate out deprecated highlight overload (#3987)
Minor thing in the type definitions I noticed. The .js makes it clear that the old API looks like `highlight(lang, code, ignoreIllegals)`, and the new API looks like `highlight(code, {lang, ignoreIllegals})`. The types on the other hand imply you could do things like `highlight(code, {lang: ...}, true)` - but that `true` would be ignored at runtime. So this separates the two forms into function overloads, and adds a `/** @deprecated */` tag to the old form so IDEs will hint not to use it.
1 parent 4b45a2b commit 8e61102

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Developer Tool:
4141

4242
- enh(tools): order CSS options picklist [David Schach][]
4343
- enh(tools): remove duplicate CSS options [David Schach][]
44+
- (typescript): deprecate old `highlight` API [Misha Kaletsky][]
4445

4546
Themes:
4647

@@ -279,6 +280,7 @@ Grammars:
279280
[Mousetail]: https://github.com/mousetail
280281
[Gabriel Gonçalves]: https://github.com/KTSnowy
281282
[Nikita Sobolev]: https://github.com/sobolevn
283+
[Misha Kaletsky]: https://github.com/mmkal
282284

283285
## Version 11.5.0
284286

types/index.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ declare module 'highlight.js' {
2929
}
3030

3131
interface PublicApi {
32-
highlight: (codeOrLanguageName: string, optionsOrCode: string | HighlightOptions, ignoreIllegals?: boolean) => HighlightResult
32+
highlight(code: string, options: HighlightOptions): HighlightResult
33+
/** @deprecated use `higlight(code, {lang: ..., ignoreIllegals: ...})` */
34+
highlight(languageName: string, code: string, ignoreIllegals?: boolean): HighlightResult
3335
highlightAuto: (code: string, languageSubset?: string[]) => AutoHighlightResult
3436
highlightBlock: (element: HTMLElement) => void
3537
highlightElement: (element: HTMLElement) => void

0 commit comments

Comments
 (0)