我有以下表达式:
import { persistState } from 'redux-devtools';
const enhancer = compose(
applyMiddleware(thunk, router, logger),
DevTools.instrument(),
persistState(
window.location.href.match(/[?&]debug_session=([^&]+)\b/)
)
);
我得到一个参数以匹配函数并出现以下错误
“RegExpMatchArray”类型的参数不可分配给“字符串”类型的参数。将字符串与正则表达式匹配,并返回包含该搜索结果的数组。(方法) String.match(regexp: RegExp): RegExpMatchArray (+1 重载)
VSCode 中的 peek 定义显示:
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.
*/
如我所见,参数是 RegExp 类型,定义中的参数也是。那为什么会出错呢?