Reputation: 6911
I just started converting JavaScript to TypeScript, and this line:
var re = new RegExp(/<script>(<h2.*?)<\/script>/g);
is showing error :
Augument of type 'RegEx' is not assignable to parameters of type 'string'
How to fix it?
Upvotes: 2
Views: 5190
Reputation: 221392
The syntax you have is duplicative -- it creates a RegExp using the built-in syntax, then creates another RegExp via the constructor function. You can write either of these instead (they are equivalent):
var re = /<script>(<h2.*?)<\/script>/g;
or
var re = new RegExp('<script>(<h2.*?)<\/script>', 'g');
Upvotes: 6