4

I have a javascript function that I am trying to convert to typescript. Here's a part of the function:

// needs Markdown.Converter.js at the moment (function () { var util = {}, position = {}, ui = {}, doc = window.document, re = window.RegExp, 

I am getting an error telling me that: The property RegExp does not exist on type Window. Is there any kind of definition file that I could include for window?

2 Answers 2

5

You may try passing global arguments to the anonymous block:

(function(window, document) { var re = window.RegExp; console.log(re); })(window, document);
Open console...

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks very much. Works perfectly. I will accept in 7 mins.
2

Just FYI, you don't need to use window for RegExp and in fact its bad practice because you are converting your JS Environment (Node.js / Browser) independent code to Browser specific code for no reason. Its like using global.RegExp in node.js when you clearly don't need to use global. I would do :

// needs Markdown.Converter.js at the moment (function () { var util = {}, position = {}, ui = {}, doc = window.document, re = RegExp; // No error })(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.