How to import Vanilla JS ES6 modules in TypeScript?

Nemus :

I'm trying to import this library: spotlight, which is plain JS.

In my project I created a fake d.ts:

declare module 'spotlight.js'

as suggested by VSCode, then I tried every single import combination:

import * as spotlight from 'spotlight';
import spotlight from 'spotlight';
import { spotlight } from 'spotlight';

but inside my code the spotlight expression is always an empty object.

What am I missing?

x00 :

As @Shinigami pointed out - there is an open issue. As I see it, right now, there is no elegant way to import the Spotlight object without modifications to the library (it also seems that npm run build doesn't help much). But, judging by the code, the Spotlight is accessible through window. So it should be possible to use it like so

import "spotlight"
window.Spotlight.show(...)

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=7141&siteId=1
Recommended