Typescript JSPM&x2B;打字脚本+;Photosweep:如何成功导入和使用库?

Typescript JSPM&x2B;打字脚本+;Photosweep:如何成功导入和使用库?,typescript,jspm,photoswipe,Typescript,Jspm,Photoswipe,我试图在我的JSPM和TypeScript项目中使用该库,但没有成功(我在这里流血…) 使用修改过的Photosweep版本定义文件(原始版本不起作用-得到“Photosweep未定义”),我得出以下结论: declare var PhotoSwipe: PhotoSwipe.IPhotoSwipeStatic; declare var PhotoSwipeUI_Default: PhotoSwipeUI_Default.IPhotoSwipeUI_DefaultStatic; declare

我试图在我的JSPM和TypeScript项目中使用该库,但没有成功(我在这里流血…)

使用修改过的Photosweep版本定义文件(原始版本不起作用-得到“Photosweep未定义”),我得出以下结论:

declare var PhotoSwipe: PhotoSwipe.IPhotoSwipeStatic;
declare var PhotoSwipeUI_Default: PhotoSwipeUI_Default.IPhotoSwipeUI_DefaultStatic;

declare module PhotoSwipe {
    ...
    interface IPhotoSwipeStatic {

        new <T extends Options> (pswpElement: HTMLElement,
            uiConstructor: (new (pswp: PhotoSwipeInstance<T>, framework: UIFramework) => UI<T>) | boolean,
            items: PhotoSwipe.Item[],
            options: T): PhotoSwipeInstance<T>;
    }
}

declare class PhotoSwipeInstance<T extends PhotoSwipe.Options> {
    ...
}


declare module PhotoSwipeUI_Default {
    ...
    interface IPhotoSwipeUI_DefaultStatic {

        new (pswp: PhotoSwipeInstance<Options>, framework: PhotoSwipe.UIFramework): PhotoSwipeUI_DefaultInstance;
    }
}

declare class PhotoSwipeUI_DefaultInstance implements PhotoSwipe.UI<PhotoSwipeUI_Default.Options> {
    ...
}
导入“Photoswip”=>我得到参考错误:未定义Photosweep

(二)

从“Photosweep”导入{Photosweep,PhotosweepUI_Default};
=>我得到类型错误:Photosweep\u 1.Photosweep不是构造函数

有人吗


我知道可能已经晚了,但这里有一个解决方案:

require([ 
        'path/to/photoswipe.js', 
        'path/to/photoswipe-ui-default.js' 
    ], function( PhotoSwipe, PhotoSwipeUI_Default ) {

    //      var gallery = new PhotoSwipe( someElement, PhotoSwipeUI_Default ...
    //      gallery.init() 
    //      ...

});
来源-

此外,在执行以下操作之前,请不要忘记导入某些文件:

import 'photoswipe/dist/photoswipe.css';
import 'photoswipe/dist/default-skin/default-skin.css';
我试图通过使用全局类型和简单类型的TypeScript方式来实现这一点:

import { PhotoSwipe, PhotoSwipeUI_Default } from 'photoswipe';
但它不起作用。我犯了和你一样的错误

祝你好运

是的,我用webpack测试了它,但不是JSPM

npm install photoswipe
npm install --save @types/photoswipe
从npm安装Photosweep及其类型定义

import photoSwipe from 'photoswipe'
然后您可以使用上面的导入语句来使用它

希望这会有所帮助

npm install photoswipe
npm install --save @types/photoswipe
import photoSwipe from 'photoswipe'