Skip to content

String.replace() : typescript displays wrong message when 2nd argument is a number #13889

@abenhamdine

Description

@abenhamdine

TypeScript Version: 2.1.5

Code

const myString = 'foo';
const myNumberThatShouldBeAString = 123;
myString.replace('a123', myNumberThatShouldBeAString);

Expected behavior:

Error on 2nd argument with message "Argument of type Number is not assignable to parameter of type 'String'.

Actual behavior:

Error on 1st argument with message "Argument of type '"a123"' is not assignable to parameter of type 'RegExp'."

Indeed, there's no signature for String.replace() in lib.es6.d.ts with number as 2nd argument, so Typescript should find error on the latter, and not on the first argument, which matches one of the signatures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions