microsoft / microsoft/TypeScript
`.call` selects the wrong overload for `String.prototype.replace`
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: v3.3.1 and v3.4.0-dev.20190206
Search Terms: call replace overload
Code
String.prototype.replace.call(
'one string',
/a/g,
'two string', // this line errors
);
It's worth noting that this is in a JS file, not a TS file, but I'm using allowJs and checkJs.
Expected behavior:
No error.
Actual behavior:
errors with error TS2345: Argument of type '"two string"' is not assignable to parameter of type '(substring: string, ...args: any[]) => string'
Playground Link: http://www.typescriptlang.org/play/#src=String.prototype.replace.call(%0D%0A%20%20%20%20'one%20string'%2C%0D%0A%20%20%20%20%2Fa%2Fg%2C%0D%0A%20%20%20%20'two%20string'%2C%0D%0A)%3B but the error doesn't seem to show up there.
Related Issues: no
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided JavaScript repro using String.prototype.replace.call, with allowJs and checkJs enabled, and trace how the replace overload is selected. Confirm the behavior against the reported TypeScript versions and verify that the call accepts the replacement string without TS2345 while preserving the existing overload behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100