SolvedDefinitelyTyped @types/jquery giving breaking solution while Gulp build
✔️Accepted Answer
Also getting an error after upgrading to the latest jquery typings:
Error at node_modules/@types/jquery/index.d.ts:2364:84: Cannot find name 'Iterable'.
Reverting to "@types/jquery": "2.0.47",
fixed my build.
Other Answers:
@Parth2402patel @mustafasadikot @klaask
Could you guys post repros?
@Simon-Briggs @rvanmarkus
This happens if you're targeting es5
. You'll need to add es2015.iterable
to your lib
in tsconfig.json
.
"lib": [
"dom",
"es5",
"scripthost",
"es2015.iterable"
],
"target": "es5",
Alternatively, you just change your target to es6
.
@MichalMeszaros
jqXHR
in the callback is currently annotated incorrectly. I'll put in a PR to fix it. Afterwards, you'll be able to use it without additional annotations.
$.ajax({ url: url }).fail((jqXHR, textStatus, errorThrown) => { });
There's multiple issues reported in this thread.
Iterable
If you're getting an error similar to
Error at node_modules/@types/jquery/index.d.ts:2364:84: Cannot find name 'Iterable'.
You need to add es2015.iterable
to lib
in your tsconfig.json
.
Unsupported TypeScript Version
@types/jquery
requires TypeScript 2.3 or higher.
If you're getting errors similar to
error TS2314: Generic type 'Deferred<TResolve, TReject, any, TNotify>' requires 4 type argument(s).
error TS1005: ',' expected.
You need to upgrade to typescript@2.3
or later.
If these solutions are not an option for you, you can drop back to 2.x typings
"@types/jquery": "<2.2",
@paulvanbrenk could we get this issue closed? There's multiple issues in this thread that are likely resolved. If users are still having issues with the latest @types/jquery
published, they're probably better off opening a new issue focused on their problem.
Resolve to me:
"target": "es6"
@mikehaas763 You wrote above that you were wondering if there was an official way of defining the Iterable
interface for libs that depends on the environment. Did you ever find any other way?
I think the solution proposed by @leonard-thieu is a bit problematic, because when adding the es2015.iterable
lib, it gives you much more than just the Iterable
interface (See https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es2015.iterable.d.ts). E.g it extends Array
with methods like entries()
, keys()
and values()
which are not available if you target ES5
like many of us do.
@tdreyno
@types/jquery
package and had problems.This errors are too many.
I am facing this issue today when used latest version.
What might be going wrong?
Error - typescript - node_modules@types\jquery\index.d.ts(4306,101): error TS2304: Cannot find name 'any'.
Error - typescript - node_modules@types\jquery\index.d.ts(4455,36): error TS2314: Generic type 'Deferred<TResolve, TRej
ect, any, TNotify>' requires 4 type argument(s).
Error - typescript - node_modules@types\jquery\index.d.ts(4456,36): error TS2314: Generic type 'Event<TTarget, EventTar
get, TData>' requires 3 type argument(s).
Error - typescript - node_modules@types\jquery\index.d.ts(4457,41): error TS2314: Generic type 'Event<TTarget, EventTar
get, TData>' requires 3 type argument(s).
Error - typescript - node_modules@types\jquery\index.d.ts(4458,36): error TS2314: Generic type 'Deferred<TResolve, TRej
ect, any, TNotify>' requires 4 type argument(s).
Error - typescript - node_modules@types\jquery\index.d.ts(4459,37): error TS2314: Generic type 'AjaxSettings<TContext,
any>' requires 2 type argument(s).
Error - typescript - node_modules@types\jquery\index.d.ts(4461,43): error TS2694: Namespace 'JQuery' has no exported me
mber 'Coordinates'.
Error - typescript - node_modules@types\jquery\index.d.ts(4463,28): error TS2314: Generic type 'jqXHR<TResolve, any>' r
equires 2 type argument(s).
Error - typescript - node_modules@types\jquery\index.d.ts(4464,35): error TS2314: Generic type 'Promise<TResolve, TReje
ct, any, TNotify>' requires 4 type argument(s).
Error - typescript - node_modules@types\jquery\index.d.ts(4465,53): error TS2694: Namespace 'JQuery' has no exported me
mber 'NameValuePair'.
Regards,
Parth Patel