KeyLines and TypeScript
Contents
Introduction
KeyLines supports the use of TypeScript. You can write your application in TypeScript to make use of features such as intellisense, compile-time type checking and context-sensitive API documentation.
TypeScript is a strongly typed, open source superset of JavaScript that is compiled to simple JavaScript and runs on any browser. It features type annotations that let you record contracts of functions and variables in a lightweight way. It lets you use existing JavaScript code, import other JavaScript libraries, and call TypeScript code from JavaScript.
We regularly test our definition files against the latest available TypeScript version.
Using TypeScript with KeyLines
When using JavaScript libraries (such as KeyLines) with TypeScript, it’s useful to have the type definitions for each library. KeyLines comes with detailed type definitions that are updated every time there's a change to the KeyLines API. Including these definitions in your project makes coding in TypeScript much easier.
The easiest way to include the TypeScript files is by installing KeyLines as a package. This makes the TypeScript definitions available in your code automatically.
For examples of how to import KeyLines as a package using the npm package manager, see the 'Using KeyLines...' tutorials in the Installing KeyLines section of our documentation.
Using KeyLines type definitions
You can use KeyLines normally and TypeScript will provide type checking of your application code using the KeyLines type definitions.
You can also import types from the KeyLines package to help you develop more complex
TypeScript applications. For example, to import KeyLines along with the Chart
and
TimeBar
types, you can use the following import pattern:
import KeyLines, { Chart, TimeBar } from 'keylines/esm';
If you're using many types, it might be more convenient to access them by a namespace. For example:
import KeyLines, * as kl from 'keylines/esm';
TypeScript demos
Although most of our demos are not written in TypeScript, we have used TypeScript definitions to write source code for the Angular Integration demo.