Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
typescript文件中的外部jQuery库_Jquery_Typescript_Smartadmin - Fatal编程技术网

typescript文件中的外部jQuery库

typescript文件中的外部jQuery库,jquery,typescript,smartadmin,Jquery,Typescript,Smartadmin,我正在从事一个Asp.net MVC项目,该项目具有Smartadmin主题和Typescript,带有用于Dom操作的JQuery类型,有一个名为SmartMessageBox的JQuery库用于提示消息,有没有简单的方法在我的Typescript文件中使用该库,因为我 生成错误:类型“JQueryStatic”上不存在属性“SmartMessageBox”如果消息框仅在一个文件中使用,最简单的解决方案是在文件顶部添加类似以下内容: declare const jQuery: JQuerySt

我正在从事一个Asp.net MVC项目,该项目具有Smartadmin主题和Typescript,带有用于Dom操作的JQuery类型,有一个名为SmartMessageBox的JQuery库用于提示消息,有没有简单的方法在我的Typescript文件中使用该库,因为我
生成错误:类型“JQueryStatic”上不存在属性“SmartMessageBox”

如果消息框仅在一个文件中使用,最简单的解决方案是在文件顶部添加类似以下内容:

declare const jQuery: JQueryStatic & {
    // *** Choose one of the following ***
    // Most basic:
    SmartMessageBox: any;
    // Better (assuming SmartMessageBox is a function):
    SmartMessageBox(/*param type info*/): /*return type or void*/;
};
这表示
jQuery
是一个全局对象,其类型是接口
JQueryStatic
和描述
SmartMessageBox
的接口的类型


如果消息框或其他“智能管理”类型在多个文件中使用,则应考虑编写.d.ts文件。和应该有助于确定要做什么。将文件保存在
/typings/smart admin/index.d.ts
下,并在tsconfig.json中添加以下内容:

{
    "compilerOptions": {
        "typeRoots": ["./node_modules/@types", "./typings"]
    }
}

这告诉编译器在
/typings
以及
/node\u modules/@types
(从npm安装的
@types
包的默认位置)下查找类型定义。

必须为SmartMessageBox创建一个d.ts文件。

您可以编写描述库的声明文件。如果您在项目文档中发布链接,我可能会有所帮助,但我无法在简单的搜索中找到库。您需要该插件的类型定义,或者您可以在使用
SmartMessageBox
属性之前将
jQuery
转换为
any
,例如
(jQuery as any).SmartMessageBox(args)
@Roomy这是一种可能性,但不是很安全,如果库很简单,编写声明可能会有回报。甚至可能将它们贡献给明确键入的;)不幸的是,它是由主题创建者编写的库,我想,我在任何地方都找不到它