How to use Aurelia third party plugin with without typescript definition file?

心不动则不痛 提交于 2019-12-10 11:13:54

问题


I am new to Aurelia and Typescript. I am trying to use a the aurelia-dialog plugin inside of my project. I have follow all the necessary steps and am getting an error "cannot find module "aurelia-dialog". The offending line is

import {DialogService, DialogController} from "aurelia-dialog";

I am pretty sure all of the config is set up correctly because this is my only error. I have

aurelia.use
  .standardConfiguration()
  .developmentLogging()
  .plugin('aurelia-dialog');

Do I need to create a typescript definition file for this to work, if so how? Or am I missing something and this should work as-is?


回答1:


Looks like the aurelia-dialog build hasn't been configured to produce TypeScript definition files yet. This will probably be added soon. In the meantime you could add an aurelia-dialog.d.ts file to your project with the following:

declare module 'aurelia-dialog' {
  export class DialogService {
    open(settings: any): Promise;
  }
  export class DialogController {
    constructor(renderer, settings, resolve, reject);
    ok(result: any): Promise<DialogResult>;
    cancel(result: any): Promise<DialogResult>;
    error(message): Promise<DialogResult>;
    close(ok: boolean, result: any): Promise<DialogResult>;
    settings: {lock: boolean, centerHorizontalOnly: boolean };
  }

  export class DialogResult {
    wasCancelled: boolean;
    output: any;
    constructor(cancelled: boolean, result: any);
  }
}


来源:https://stackoverflow.com/questions/33046339/how-to-use-aurelia-third-party-plugin-with-without-typescript-definition-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!