SPFx不能使用JQuery吗? [英] SPFx can't use JQuery?

查看:135
本文介绍了SPFx不能使用JQuery吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Yeoman创建的SPFx来开发全新的SharePoint Web部件,脚手架模板很好,添加JQuery和JQueryUI的NPM也不是一个单一的问题,我看到了 GULP SERVE >在后台运行,没有任何错误.

当我在JQWebPart.ts中添加以下行时,就会发生问题:

      import * as jQuery from 'jquery';

添加了上面的行后, GULP SERVE 会输出很长的错误列表,下面是所有错误的最后一行:

[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7502,33): error TS2314: Generic type 'Callbacks<T, Function>' requires 2 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7503,36): error TS2314: Generic type 'Deferred<TR, TJ, any, TN>' requires 4 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7504,41): error TS2314: Generic type 'Event<TTarget, EventTarget, TData>' requires 3 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7505,36): error TS2314: Generic type 'Deferred<TR, TJ, any, TN>' requires 4 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7506,37): error TS2314: Generic type 'AjaxSettings<TContext, any>' requires 2 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7510,28): error TS2314: Generic type 'jqXHR<TResolve, any>' requires 2 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7511,35): error TS2314: Generic type 'Promise<TR, TJ, any, TN>' requires 4 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7517,32): error TS2314: Generic type 'PlainObject<T, any>' requires 2 type argument(s).
[16:54:06] Finished subtask 'tslint' after 3.95 s
[16:54:06] Error - 'typescript' sub task errored after 3.95 s
 "TypeScript error(s) occurred."

当我尝试使用JQuery时,我不知道Web部件发生了什么,任何机构都没有任何想法吗?

解决方案

感谢用户Rohit Waghela,已经有一种解决方案可以解决与SPFx中的JQuery相关的问题:

https://thechriskent.com/tag/sharepoint-framework/

问题是TypeScript与JQuery之间不兼容,因此底线如下:

1)删除JQuery:npm uninstall @types/jquery

2)安装兼容版本:npm install @types/jquery@2.0.48 --save-dev

I'm working on a brand new SharePoint Web Part using SPFx created by Yeoman, the scaffolding template is fine, adding the NPMs for JQuery and JQueryUI also get not a single problem, I see GULP SERVE running in the background without any errors.

The problem happens when I add the following line inside my JQWebPart.ts:

      import * as jQuery from 'jquery';

Once the line above is added the GULP SERVE outputs a very long list of errors, below are the last lines from all the errors:

[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7502,33): error TS2314: Generic type 'Callbacks<T, Function>' requires 2 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7503,36): error TS2314: Generic type 'Deferred<TR, TJ, any, TN>' requires 4 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7504,41): error TS2314: Generic type 'Event<TTarget, EventTarget, TData>' requires 3 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7505,36): error TS2314: Generic type 'Deferred<TR, TJ, any, TN>' requires 4 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7506,37): error TS2314: Generic type 'AjaxSettings<TContext, any>' requires 2 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7510,28): error TS2314: Generic type 'jqXHR<TResolve, any>' requires 2 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7511,35): error TS2314: Generic type 'Promise<TR, TJ, any, TN>' requires 4 type argument(s).
[16:54:06] Error - typescript - node_modules\@types\jquery\index.d.ts(7517,32): error TS2314: Generic type 'PlainObject<T, any>' requires 2 type argument(s).
[16:54:06] Finished subtask 'tslint' after 3.95 s
[16:54:06] Error - 'typescript' sub task errored after 3.95 s
 "TypeScript error(s) occurred."

I have no idea what is going on with my Web Part when I try to use JQuery, does any body have any ideas???

解决方案

Thanks to user Rohit Waghela, there is a solution already in place to solve issues related to JQuery in SPFx:

https://thechriskent.com/tag/sharepoint-framework/

The problem is incompatibility between TypeScript and JQuery, so the bottom line here is the following:

1) remove JQuery: npm uninstall @types/jquery

2) install compatible version: npm install @types/jquery@2.0.48 --save-dev

这篇关于SPFx不能使用JQuery吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆