Microsoft/TypeScript

`.call` selects the wrong overload for `String.prototype.replace`

Open

#29 789 ouverte le 7 févr. 2019

Voir sur GitHub
 (3 commentaires) (2 réactions) (0 assignés)TypeScript (6 726 forks)batch import
BugDomain: lib.d.tsHelp Wanted

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

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

Guide contributeur