我有以下表达:
import { persistState } from 'redux-devtools';
const enhancer = compose(
applyMiddleware(thunk, router, logger),
DevTools.instrument(),
persistState(
window.location.href.match(/[?&]debug_session=([^&]+)\b/)
)
);
我在参数上做了一个调整,使函数与下面的错误相匹配
类型'RegExpMatchArray‘的参数不能分配给'string’类型的参数。将字符串与正则表达式匹配,并返回包含该搜索结果的数组。(方法) 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类型的,定义中的参数也是这样。那为什么是错误呢?
发布于 2016-05-28 14:53:58
@NitzanTomer是对的。类型不匹配的不是匹配函数参数。当然,您可以尝试将匹配函数的返回值存储在字符串类型变量中/从:string
函数返回它/将其作为string
参数传递。
https://stackoverflow.com/questions/37500125
复制相似问题