Here is the code snippet I am working with:
import { persistState } from 'redux-devtools';
const enhancer = compose(
applyMiddleware(thunk, router, logger),
DevTools.instrument(),
persistState(
window.location.href.match(/[?&]debug_session=([^&]+)\b/)
)
);
I encountered an issue when trying to use the match function with a regular expression argument. The error message I received was:
Argument of type 'RegExpMatchArray' is not assignable to parameter of type 'string'. Matches a string with a regular expression, and returns an array containing the results of that search. (method) String.match(regexp: RegExp): RegExpMatchArray (+1 overload)
Upon further investigation using VSCode's peek definition feature, it showed:
match(regexp: string): RegExpMatchArray;
/**
* Matches a string with a regular expression, and returns an array containing the results of that search.
* @param regexp A regular expression object that contains the regular expression pattern and applicable flags.
*/
match(regexp: RegExp): RegExpMatchArray;
/**
* Replaces text in a string, using a regular expression or search string.
* @param searchValue A string that represents the regular expression.
* @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
*/
It appears that both the argument and the parameter are of type RegExp as per the definition. So why am I getting this error?