2

DefinitelyTyped has a definition for Highlight.js which defines and exports a module like so:

declare module "highlight.js"
{
    module hljs
    {
        export function highlight(
            name: string,
            value: string,
            ignore_illegals?: boolean,
            continuation?: boolean) : IHighlightResult;
        ...
    }
    export = hljs;
}

In a given typescript file, I'm attempting to import the hljs object so I can call the highlight function on it, like so:

/// <reference path="../../tsd_typings/highlightjs/highlightjs.d.ts" />

import {hljs} from 'highlight.js';

...

hljs.highlightBlock(block);

But it fails saying that error TS2305: Module '"highlight.js"' has no exported member 'hljs'.

What is the proper way to import this object so I can compile my TS files without erros and warnings?

Edy Bourne
  • 5,679
  • 13
  • 53
  • 101

1 Answers1

2

The import statement should be:

import * as hljs from 'highlight.js';

That is the equivalent of:

import hljs = require('highlight.js');

and will import the entire module as hljs.

thoughtrepo
  • 8,306
  • 2
  • 27
  • 21