Search code examples
javascripttypescriptbokehtsconfig

How to get the typescript compiler to find bokeh's "*d.ts" files


I have recently moved from Bokeh's nice, inline extension framework to their npm based out of line build system, I am trying go get my extension to build, but Bokeh installs all of the TypeScript *.ts.d in a separate tree, for example:

bash$ find node_modules -name 'serialization.*'
node_modules/@bokeh/bokehjs/build/js/types/core/util/serialization.d.ts
node_modules/@bokeh/bokehjs/build/js/lib/core/util/serialization.js
bash$ 

In the inline build system this file is imported like import { is_NDArray_ref, decode_NDArray } from "core/util/serialization".

Is there a way using tsconfig.json options to allow my extension files to continue to use core/util/serialization for import and find both the JavaScript and the TypeScript description with Bokeh's node installation layout.

The only dependency in my package.json is:

  "dependencies": {
    "@bokeh/bokehjs": "^2.3.1"
  },

Even if I change the import paths to use .../lib/..., TypeScript does not find the *.d.ts files, and if I change the import path to use .../types/... if finds the types and compiles but the linker fails to find the JavaScript. I used Bokeh's bokeh init to create my build sandbox... Thanks for any advice...


Solution

  • I found the answer in a Bokeh ticket. In a nutshell, adding:

    "paths": {
      "@bokehjs/*": [
        "./node_modules/@bokeh/bokehjs/build/js/lib/*",
        "./node_modules/@bokeh/bokehjs/build/js/types/*"
      ]
    }
    

    to the tsconfig.json file in the compilerOptions property allows imports like:

    import { is_NDArray_ref, decode_NDArray } from "@bokehjs/core/util/serialization"
    

    which seems very reasonable.