【发布时间】:2016-09-26 18:37:25
【问题描述】:
我有以下表达:
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 类型,定义中的参数也是。那为什么会报错呢?
【问题讨论】:
-
你对比赛的结果做了什么?
-
请提供MCVE。
标签: typescript visual-studio-code typescript1.8 typescript-typings