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
/**
* Returns true if searchString appears as a substring of the result of converting this
* object to a String, at one or more positions that are
* greater than or equal to position; otherwise, returns false.
* @param searchString search string
* @param position If position is undefined, 0 is assumed, so as to search all of the String.
*/
- includes(searchString: string, position?: number): boolean;+ includes<SearchString extends string>(searchString: SearchString, position?: number): this is `${string}${SearchString}${string}`
/**
* Returns true if the sequence of elements of searchString converted to a String is the
* same as the corresponding elements of this object (converted to a String) starting at
* endPosition – length(this). Otherwise returns false.
*/
- endsWith(searchString: string, endPosition?: number): boolean;+ endsWith<SearchString extends string>(searchString: SearchString): this is `${string}${SearchString}`+ endsWith<SearchString extends string>(searchString: SearchString, endPosition: number): this is `${string}${SearchString}${string}`
/**
* Returns true if the sequence of elements of searchString converted to a String is the
* same as the corresponding elements of this object (converted to a String) starting at
* position. Otherwise returns false.
*/
- startsWith(searchString: string, position?: number): boolean;+ startsWith<SearchString extends string>(searchString: SearchString): this is `${SearchString}${string}`+ startsWith<SearchString extends string>(searchString: SearchString, position: number): this is `${string}${SearchString}${string}`
Changing a function from not-overloaded to overloaded has fairly pervasive effects in areas like contextual typing, generic inference, and how exactly it can be invoked when the method operand is a union
fwiw the includes here still isn't an overload
I believe the startsWith/endsWith need not be either, if that's a blocker, e.g.
startsWith<SearchStringextendsstring,Positionextendsnumber|undefined=undefined>(searchString: SearchString,position?: Position):
this isPositionextendsnumber
? `${string}${SearchString}${string}`
: `${SearchString}${string}`
template string literals are inherently combinatorially explosive, so a call like startsWith(union of 24) && endsWith(union of 24) produces a union of 576 elements, which is bad from a performance and comprehensibility perspective
this is a legitimate concern, but is it more of an issue with template literal types than the implementation of String methods? i suppose something can be said about encouraging/discouraging these combinatorial explosions though..
⚙ Compilation target
ES2015
⚙ Library
ES2015.Core
Missing / Incorrect Definition
Sample Code
playground link
Documentation Link
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
The text was updated successfully, but these errors were encountered: