eXavier eXavier - 6 months ago 158
TypeScript Question

How to import plotly.js into TypeScript?

I'm trying to import

into TypeScript. Plotly.js is installed using
. In my TypeScript file I use

import 'plotly.js';

It's OK but I'm getting error on code like

error TS2304: Cannot find name 'Plotly'

When I try

import Plotly = require('plotly.js');

I'm getting

error TS2307: Cannot find module 'plotly.js'.


Ended up with:

declare function require(moduleName: string): any;
var Plotly = require('plotly.js/lib/index-basic.js');

(Referring to index-basic.js as I need just the basic functionality, use index.js for the full library.)