Is there a typescript definition for a window?
I have a javascript function that I am trying to convert to typescript. Here's 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 the error: The RegExp property does not exist in the type window. Is there any definition file I could include for the window?
source to share
You can try passing global arguments to the anonymous block:
(function(window, document) {
var re = window.RegExp;
console.log(re);
})(window, document);
Open console...
source to share
Just FYI, you don't need to use window
for RegExp
and it's actually bad practice because you are converting independent JS Environment code (Node.js / Browser) to browser code for no reason. This is similar to use 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
})();
source to share