We have changed our pricing. Flexmonster Software License Agreement was also updated (list of changes)
All documentation
  • Introduction
  • Connecting to data source
  • Browser compatibility
  • Documentation for older versions
  • Integration with TypeScript

    This tutorial will help you integrate Flexmonster with TypeScript.

    Prerequisites

    Run the sample project from GitHub

    Download the sample project with the flexmonster create command. You can choose a TypeScript or TypeScript + webpack project:

    TypeScript

    flexmonster create typescript -r

    This command downloads the TypeScript project from GitHub and launches it in the browser. To shut down the project from the console, press Ctrl + C (Control + C on macOS).

    The sample project is located inside the flexmonster-typescript-project/ folder in your current working directory.

    If you change the contents of the main.ts file, recompile the main.js file using the following command:

    npx tsc

    TypeScript + webpack

    flexmonster create typescript webpack -r

    This command downloads the TypeScript + webpack project from GitHub and launches it in the browser. To shut down the project from the console, press Ctrl + C (Control + C on macOS).

    The sample project is located inside the flexmonster-typescript-webpack-project/ folder in your current working directory.

    Integrate Flexmonster into a TypeScript application

    Step 1. For integration with TypeScript, we will need Flexmonster type definitions, which can be found in the flexmonster npm package. Download the package by running the following command inside your project:

    flexmonster add js-flexmonster

    The command downloads flexmonster to the node_modules/ folder and adds it as an npm dependency to the package.json file.

    Step 2. Add Flexmonster to the types array in the tsconfig.json file:

    // ...
    "types": ["flexmonster"],
    // ...

    Step 3. Follow the steps from the Embed Flexmonster section to add Flexmonster to your project. Note that you need the Flexmonster CLI or npm tabs. 

    Step 4. Run your project to see the result.

    Example

    Here is an example of how Flexmonster integration with TypeScript can be done when the webpack bundler is used:

    index.html

    <!DOCTYPE html>
    <html>
    <body>
    <!-- Create a div container to insert the component -->
    <div id="pivotContainer"></div>

    <!-- Include main.js file -->
    <script src="main.js"></script>
    </body>
    </html>

    main.ts

    import * as Flexmonster from "flexmonster";
    import "flexmonster/flexmonster.min.css";

    const pivot = new Flexmonster({
    container: "pivotContainer",
    toolbar: true
    });

    tsconfig.json

    {
    "compilerOptions": {
    // Other configs
    "types": ["flexmonster"],
    // Other configs
    }
    }

    What’s next?

    You may be interested in the following articles: