Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript:类型为'的参数;RegExpMatchArray';不可分配给类型为';字符串';_Typescript_Visual Studio Code_Typescript1.8_Typescript Typings - Fatal编程技术网

Typescript:类型为'的参数;RegExpMatchArray';不可分配给类型为';字符串';

Typescript:类型为'的参数;RegExpMatchArray';不可分配给类型为';字符串';,typescript,visual-studio-code,typescript1.8,typescript-typings,Typescript,Visual Studio Code,Typescript1.8,Typescript Typings,我有以下的表达: import { persistState } from 'redux-devtools'; const enhancer = compose( applyMiddleware(thunk, router, logger), DevTools.instrument(), persistState( window.location.href.match(/[?&]debug_session=([^&]+)\b/) ) ); 我在参数上得

我有以下的表达:

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类型,定义中的参数也是。那为什么会出错呢?

@NitzanTomer是对的。类型不匹配的不是match functions参数。您当然尝试将匹配函数的返回值存储在字符串类型的变量中/从
:string
函数返回/将其作为
字符串
参数传递。

您对匹配结果做了什么?请提供一个。我认为这是VSCode intellisense的问题。swiggly仅位于要匹配的参数上,而整个语句
window.location.href.match(/[?&]debug\u session=([^&]+)\b/)
应具有swiggly。重新启动VSCode修复了它。谢谢@KushagraSharma,重新启动VSCode确实也是我的解决方案。你知道是否有人报告过这个错误吗?@MaximeBernard我不知道是否有人报告过这个问题。