Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Jquery and Typescript [ts] Argument of type 'string | number | string[]' is not assignable to parameter of type 'string'.

Lonnie McGill:

I have a large existing project that is being converted to typescript and will eventually be refactored and then put into Angular. The current project has a lot of Jquery in it. I have a current @types implemented into the project.

The issue is that this line


if (["Priority", "PM"].indexOf($('option:selected', this).val()) >= 0) {

is creating an error because of type definitions. I get [TS] Argument of type 'string | number | string[]' is not assignable to parameter of type 'string'. Because the indexOf is defined as "(method) Array.indexOf(searchElement: String, fromIndex?: number): number" and Jquery's .val is defined as "JQuery.val(): string | number | string[] (+1 overload)".

I need a way to override the .val definition, to just string so that I can get it to compile, for lines like this without overriding .val for the whole project. I have many lines that are like this in the project so I'm not able to just rewrite everyone of them yet. Eventually we will get rid of Jquery entirely. If anyone can point me to the right direction that would be great.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Jquery and Typescript [ts] Argument of type 'string | number | string[]' is not assignable to parameter of type 'string'.

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×