You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Like the first parameter is declared as an union, I would expect the second to be the same, at least in the lib.es5 version.
Notably, this makes the following code not compile:
// The second argument is an union of replaceValue and replacer from lib.es5constreplacementSteps: ([RegExp,string|((substring: string, ...args: any[])=>string)])[]=[[/(a|b)/gi,"a"],[/(c|d)/gi,match=>match.toUpperCase()],];letmyString="abcdef";for(const[searchValue,replacement]ofreplacementSteps)myString=myString.replace(searchValue,replacement);// TS2345 - the second parameter is considered invalid
By adding this into my declaration, the code works:
I cannot propose a solution other than my last hack, and of course the variants with Symbol would have to be taken into account. Please consider this just a note.
I am using TypeScript 5.0.4.
I have noticed the typing of
String.replace
seem oddly convoluted.From
lib.es5.d.ts
:From
lib.es2015.symbol.wellknown.d.ts
:Like the first parameter is declared as an union, I would expect the second to be the same, at least in the
lib.es5
version.Notably, this makes the following code not compile:
By adding this into my declaration, the code works:
I cannot propose a solution other than my last hack, and of course the variants with
Symbol
would have to be taken into account. Please consider this just a note.See also this: microsoft/TypeScript#54223
The text was updated successfully, but these errors were encountered: