Configuring type definitions when depending on bokehjs npm package

Since 1.1 bokehjs’ npm package configures types, but that only works for import {something} from "bokehjs". Importing individual modules requires additional configuration to make it work. I would follow the approach we use in our tests. Add this to your tsconfig.json:

https://github.com/bokeh/bokeh/blob/master/bokehjs/test/tsconfig.json#L25-L27

(just replace .. with ./node_modules/bokehjs or something that works for you) and then you will be able to import individual modules like this:

import {Document} from "@bokehjs/document"

This may also be future proof, if we decide to split bokehjs up under @bokehjs namespace. On the other hand, maybe you don’t have import individual modules and just import from “bokehjs” (Document is exported by default). This is what our examples use, but they target bundled bokehjs artifacts. Importing individual modules is useful though if you want to include only necessary modules.

Alternatively we could keep *.js and *.d.ts together to reduce the need for configuration, but importing from build/js/lib seems pretty ugly.

1 Like