mdbootstrap / perfect-scrollbar

Minimalistic but perfect custom scrollbar plugin. Get more free components with Material Design for Bootstrap UI Kit (link below)
https://perfectscrollbar.com/
MIT License
346 stars 66 forks source link

[ts] Cannot use 'new' with an expression whose type lacks a call or construct signature. #103

Open AHoxha19 opened 6 years ago

AHoxha19 commented 6 years ago

I am trying to use the plugin with the aurelia framework but i always got this TypeScript error:

When i import the plugin like this:

import * as PerfectScrollbar from 'perfect-scrollbar';
const ps = new PerfectScrollbar('.scroll-nav');

it works but TypeScript always give me this error:

[ts] Cannot use 'new' with an expression whose type lacks a call or construct signature.

If i import the plugin like it's written in the doc:

import PerfectScrollbar from 'perfect-scrollbar;
const ps = new PerfectScrollbar('.scroll-nav');

I don't have the error in TypeScript but the plugin is not working. bug-ps

I tried many ways to initialize and import it but it still does not work. Has anyone an idea ?

Config: I use Aurelia, Aurelia CLI and RequireJS as a loader.

lrech commented 5 years ago

We are also using Aurelia and we had to modify the perfect-scrollbar.d.ts to get this to work.

We removed the export default PerfectScrollbar line and replace it with an export = PerfectScrollbar above the declare class PerfectScrollbar

eg.

export = PerfectScrollbar;

declare class PerfectScrollbar {
  constructor(element: string | HTMLElement, options?: PerfectScrollbar.Options);

This also meant that we need needed to change the import statement to this: import * as PerfectScrollbar from 'perfect-scrollbar';

I hope this helps. I'm not sure if this is a valid change for use in other frameworks but it is now working for us.

Update: With the above changes in place we also found that on a release build with webpack we needed to remove the "module" property from package.json file to force webpack to use 'dist/perfect-scrollbar.common.js'