【发布时间】:2016-07-09 19:34:48
【问题描述】:
我正在尝试在我的 JSPM 和 TypeScript 项目中使用 PhotoSwipe 库但没有成功(我在这里流血......)。
使用来自DefinitelyTyped 的 PhotoSwipe 的修改版本定义文件(原始版本不起作用 - 得到“PhotoSwipe 未定义”),我想出了这个:
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> {
...
}
尝试导入它,我似乎不知道如何创建 PhotoSwipe 的实例:
const photoSwipe = new PhotoSwipe(pswpElement, PhotoSwipe.PhotoSwipeUI, items, options);
1)
declare module "photoswipe" {
export = { PhotoSwipe, PhotoSwipeUI_Default };
}
和import "photoswipe"; => 我得到 ReferenceError: PhotoSwipe 未定义
2)
declare module "photoswipe" {
export var PhotoSwipe: PhotoSwipe.IPhotoSwipeStatic;
export var PhotoSwipeUI_Default: PhotoSwipeUI_Default.IPhotoSwipeUI_DefaultStatic;
}
和import { PhotoSwipe, PhotoSwipeUI_Default } from "photoswipe";
=> 我得到 TypeError: photoswipe_1.PhotoSwipe 不是构造函数
有人吗?
【问题讨论】:
标签: typescript jspm photoswipe