0

As a novice user of typescript (but an experienced user of Bokeh), I'm trying to take one of the BokehJS examples and run it standalone -- that is outside of the file hierarchy of the Bokeh git repo.

So for example, if I want to run the burtin example, I copy the .ts, .html and tsconfig.json (from the top-level of the examples directory) into a new folder. I can then modify the link and script tags in the .html file to point to local copies of the corresponding resources. When I attempt to run tsc burtin.ts, I get the following errors:

$ tsc burtin.ts
burtin.ts(2,16): error TS2304: Cannot find name 'Bokeh'.
burtin.ts(2,16): error TS2503: Cannot find namespace 'Bokeh'.
burtin.ts(3,27): error TS2304: Cannot find name 'Bokeh'.
burtin.ts(5,18): error TS2503: Cannot find namespace 'Bokeh'.
burtin.ts(6,16): error TS2503: Cannot find namespace 'Bokeh'.
burtin.ts(8,24): error TS2304: Cannot find name 'Bokeh'.
burtin.ts(9,3): error TS2304: Cannot find name 'Bokeh'.
burtin.ts(10,3): error TS2304: Cannot find name 'Bokeh'.

How do I tell the typescript compiler where to find Bokeh? The tsconfig.json in the burtin example has the following:

{
  "extends": "../tsconfig.json",
  "files": [
    "../../src/coffee/api/typings.d.ts",
    "burtin.ts"
  ]
}

and perhaps the typings.d.ts tells the compiler where to look for exported BokehJS names, but it's unclear if I need to have the full bokeh source base to compile the example (the typings.d.ts file isn't included when you conda install bokeh).

Any insight into how you would set up this example and run it standalone would be appreciated.

UPDATE: Even though tsc throws the errors, it still produces a working burtin.js and the html page displays properly. I'm just unclear if there is a more optimal way to setup the development environment.

Eugene Pakhomov
  • 9,309
  • 3
  • 27
  • 53
JoshAdel
  • 66,734
  • 27
  • 141
  • 140

1 Answers1

1

Running tsc burtin.ts disregards tsconfig.json. You should be running tsc -p tsconfig.json (or tsc -p .) instead. This way you will get an error when typings (d.ts files) aren't found. Typings should be a part of conda and npm packages, but it looks like we have a regression here, so for now you will have to resort to cloning bokeh's repository or coping over *.d.ts files. Those are necessary only for compilation and aren't used at runtime. Having typings or not, TypeScript will still compile a *.ts file and produce a valid *.js file, as long as there are no syntax or other fundamental errors and noEmitOnError is set to false. This is because TypeScript's type system is fully erased before generating a *.js file and no code is generated based on the types of a program.

Given that TypeScript support in bokehjs is under active development, and bokehjs is being rewritten from the ground up in TypeScript, there should be major improvements available in this area in a few weeks. In particular, new auto-generated typings covering the entire library will be provided. Ideally there will be a single bokeh.d.ts file to include.