2

的参数,我有以下表现:打字稿:类型RegExpMatchArray'的参数是不能分配给类型“字符串”

import { persistState } from 'redux-devtools'; 

const enhancer = compose(
    applyMiddleware(thunk, router, logger), 
    DevTools.instrument(), 
    persistState(
    window.location.href.match(/[?&]debug_session=([^&]+)\b/) 
) 
); 

我得到一个swiggly的参数,下面的错误

匹配功能

'RegExpMatchArray'类型的参数不可分配给参数 类型'string'。与正则表达式匹配字符串,并返回包含该搜索结果的数组。 (方法) String.match(正则表达式:正则表达式):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. 
    */ 

正如我看到的那样,参数的类型的正则表达式定义中的参数也是如此。那为什么这个错误?

+1

你在做什么与比赛的结果? –

+0

请提供[MCVE](http://stackoverflow.com/help/mcve)。 –

回答

1

@NitzanTomer是对的。这不是匹配函数参数的类型不匹配。你当然试图将匹配函数的返回值存储在一个字符串类型变量中/从:string函数返回它,或者将它作为string参数传递。

+1

我认为这是VSCode intellisense的问题。 swiggly只是在匹配的参数上,而整个语句'window.location.href.match(/ [?&] debug_session =([^&] +)\ b /)'应该具有这种灵活性。 重新启动VSCode修复它。 –

+0

谢谢@KushagraSharma,重新启动vscode也是我的解决方案。你有任何想法,如果这个错误已被报告? – MaximeBernard

+0

@MaximeBernard我不知道这个问题是否有报道。 –

相关问题