atom-typescript icon indicating copy to clipboard operation
atom-typescript copied to clipboard

Argument of type 'string is not assignable to parameter of type RegExp

Open csmrkid opened this issue 10 years ago • 5 comments

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.

csmrkid avatar Mar 20 '16 11:03 csmrkid

I am getting this same message, just as described above.

jtc10005 avatar Aug 31 '16 14:08 jtc10005

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!

pratham-p avatar Dec 05 '16 23:12 pratham-p

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 avatar Dec 16 '16 15:12 johncoffee

@johncoffee is right. The message is misleading, that is the real defect.

ocala avatar Apr 30 '17 08:04 ocala

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

github-actions[bot] avatar Jan 01 '20 00:01 github-actions[bot]