What to do if a typings (or tsd) is not available?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 09:10:00

If your primary concern is just to get rid of the errors, you can simply write declare var MyUntypedLibrary: any; above your code, where MyUntypedLibrary is the name of the global reference to your dependency.

If you need this reference in several files and don't want to repeat yourself, you could write it in the top of any file, above any namespaces, and it would be available to the whole project. If you have many untyped dependencies, it would probably be a good idea to have a separate ts-file where you define these.

Note: This works fine when using local modules. I'd guess this might be more troublesome if one is using external modules and want to have one place to define an implicit dependency for them all, but then again each module should handle their own dependencies internally anyway.

Although the best would be to create your own definition file (.d.ts), clone the https://github.com/DefinitelyTyped/DefinitelyTyped repository, add to it, and create a pull request back to their trunk; you way want a quicker solution here.

You could write your own simplest definition file corresponding to your need, and add it to your project, hence keeping you away from waiting that definitions are accepted / read to merge in DefTyped trunk.

However you could write your simple def file, and create the pull request anyway, small def file is better than no def file ;)

Additional instructions to create your definition : http://definitelytyped.org/guides/creating.html

Simple example:

 interface JQuery {

    /* wrapped plugins */

    dynatree(options: any): any;

    multiselect(): JQuery;
    multiselect(MultiSelectSettings): any;
    multiselect(command: string): any;

    ajaxSubmit(options: any);
    layout(options: any);

    colpick(options?: any);
    colpickHide();

    idcDataTable(options?: any);

    dragscrollable(options: any);

    /* wrapped plugins - END */
}

interface JQueryStatic {
    layout: any;

    fileDownload: any;

    pnotify: any;

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