silvermine / videojs-quality-selector

MIT License
183 stars 54 forks source link

Unable to import plugin in TypeScript project (stencil components) #55

Closed maxpain84 closed 4 years ago

maxpain84 commented 4 years ago

Hi,

simple

import '@silvermine/videojs-quality-selector';

not working. I can not find that anything has been exported, how this plugin is intended to be used within typescript projects?

Thank you!

clixmat commented 4 years ago

I have the same problem

yokuze commented 4 years ago

The README in this project says:

For videojs to use the plug-in, the plugin needs to register itself with the instance of videojs. This can be accomplished by:

var videojs = require('videojs');

// The following registers the plugin with `videojs`
require('@silvermine/videojs-quality-selector')(videojs);

So you can't just import the plugin without doing anything with it. After you import it, you have to call the imported function and pass an instance of video.js.

As to whether or not importing actually imports, it depends on your TypeScript compiler settings. This project uses CommonJS modules, so your TypeScript config needs esModuleInterop set to true. Also, this project does not have type definitions yet, so you will at least need to:

declare module '@silvermine/videojs-quality-selector' {
  // Whatever types you want here. At the least:
   const x: any;
   export = x;
}

in a definition file somewhere if you are using the strict / noImplicityAny compiler option.