eXavier eXavier - 3 months ago 77
TypeScript Question

How to import plotly.js into TypeScript?

I'm trying to import

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

import 'plotly.js';


It's OK but I'm getting error on code like
Plotly.<member>
:

error TS2304: Cannot find name 'Plotly'


When I try

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


I'm getting

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

Answer

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.)