8000 Overloads for String.prototype.split method by EzioMercer · Pull Request #61827 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

Overloads for String.prototype.split method #61827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Define overloads
  • Loading branch information
EzioMercer committed Jun 5, 2025
commit 1492e256812fbe254561d1ea791b1ce53b32a848
20 changes: 20 additions & 0 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4577,3 +4577,23 @@ interface Date {
*/
toLocaleTimeString(locales?: string | string[], options?: Intl.DateTimeFormatOptions): string;
}

type Split<Source extends string, Separator extends string> = Source extends `${infer Left}${Separator}${infer Right}`
? [...(string extends Left ? string[] : [`${Left}`]), ...Split<Right, Separator>]
: Source extends ""
? Separator extends ""
? []
: [""]
: string extends Source
? string[]
: [Source];

interface String {
split<Source extends string, Separator extends string>(
this: Source,
separator: Separator,
limit?: undefined,
): Split<Source, Separator>;

split(separator: string | RegExp, limit: 0): [];
}
0