If you know how to fix the issue, make a pull request instead.
@types/jquery package and had problems.Definitions by: in index.d.ts) so they can respond.Versions:
[email protected]
@types/[email protected]
[email protected]
Code:
import * as $ from "jquery";
function test(selector: string | string[]) {
const selected = $(selector);
selected.addClass('test');
return selected;
}
test(".test");
Error:
Error shown here $(selector);
Argument of type 'string | string[]' is not assignable to parameter of type 'PlainObject<any>'.
Type 'string' is not assignable to type 'PlainObject<any>'.
(parameter) selector: string | string[]
Example: Stackblitz
Also got something weird with .on and the PlainObject, but can't reproduce.
While this does reveal a bug with the declarations, the code as written might not have intended behavior. Calling $(string[]) results in a jQuery object containing strings and not selected elements. Also, $(string[]) is undocumented and possibly unsupported by jQuery.
Even if I change it to string | HTMLElement it result in (also with Element):
Argument of type 'string | HTMLElement' is not assignable to parameter of type 'PlainObject<any>'.
Type 'string' is not assignable to type 'PlainObject<any>'.
(parameter) selector: string | HTMLElement
Right. I'm looking into it.
Will be fixed by #29612. Thanks for reporting this!
Sorry that this took so long. This fix required bumping the required TypeScript version to 2.8, so I tried to squeeze in as many updates as I could for 2.3 before bumping the TypeScript version.
Awesome, thank you!
This will actually need to be delayed until TypeScript 3.1 features become available on DefinitelyTyped. Sorry!
Is there any plan when this might happen?
@andy-ms can give you a timeline for that.
The decision was made to reject the fix for this problem as it would bump up the required TypeScript version. Is there a workaround such as extending the JQueryStatic interface?
The odd thing is that my code compiled against the latest version of the jq definitions when using tsc 3.0.3, but upgrading to 3.3 caused this error to present.
I'm getting the error as well using string | HTMLElement (which is valid), latest rev "@types/jquery": "^3.5.1" and [email protected]
the link above for the rejection is broken. Too bad there isn't a fix.
Most helpful comment
Will be fixed by #29612. Thanks for reporting this!
Sorry that this took so long. This fix required bumping the required TypeScript version to 2.8, so I tried to squeeze in as many updates as I could for 2.3 before bumping the TypeScript version.