Argument of type 'string is not assignable to parameter of type RegExp
Dear developers,
Here is my code
public test(url: string, pageSize: number, pageNumber: number, columnName: string, direction: string, term: string): Observable<ResponseData<T[]>> {
return this.http.get(this.getUrl(url)
.replace('{columnName}', columnName)
.replace('{pageSize}', pageSize) <-----error , Argument of type 'string is not assignable to parameter of type RegExp
.replace('{pageNumber}', pageNumber)
.replace('{direction}', direction)
.replace('{term}', term)
, this.restApioptions
).map(res => <ResponseData<T[]>>res.json())
.catch(this.logger.log);
}
public getUrl(url:string):string{
return this.TargetUrl+url;
}
There is an error message Argument of type 'string is not assignable to parameter of type RegExp. However, no matter what I put at <--error spot, it will show the same error.
If I replace calling this.getUrl(url) to a pure string like "xx".replace(.... then the error will be gone.
I have no idea why this happened, because the getURL() will return a string anyway. I found no error in my compiler console and the script runs without any error.
I am getting this same message, just as described above.
Hi, I am doing exactly same thing (Getting a URL from parameter and replacing the placeholders) for the "replace" method. Requesting all of you to please let us know how to resolve this or if there is any workaround to this problem? Thanks!
The error message is confusing, but I think the problem here is thatpageSize is a number.
A workaround that should work in your case:
.replace('{pageSize}', pageSize+'') or .replace('{pageSize}', pageSize.toString())
@johncoffee is right. The message is misleading, that is the real defect.
This issue has been marked as stale because it did not have any activity for the last 90 days or more. Remove the stale label or comment or this will be closed in 14 days