Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'valHooks' does not exist on type 'JQueryStatic'

I am in the process of upgrading my javascript code to TypeScript and I am facing issue with the following javascript function.

var PreserveLinebreakInTextArea = function () {
           $.valHooks.textarea = { get: function (elem) { return elem.value.replace(/\r?\n/g, "\r\n"); } };
        }

I am using the above method for preserving the line break in text area control. When I use this method in typescript file, I got the following error,

enter image description here

Any suggestion to fix this issue is appreciated.

like image 468
JGV Avatar asked Nov 28 '22 23:11

JGV


1 Answers

You can either write:

  var PreserveLinebreakInTextArea = function () {
       $['valHooks'].textarea = { get: function (elem) { return elem.value.replace(/\r?\n/g, "\r\n"); } };
  }

to keep tsc happy or you can extend JQueryStatic interface like this

interface JQueryStatic {
    valHooks: any;
}
like image 129
Martin Vseticka Avatar answered Dec 01 '22 14:12

Martin Vseticka