Skip to content

feat: refine .split() return type #56834

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions src/lib/es2015.symbol.wellknown.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ interface RegExp {
* @param limit if not undefined, the output array is truncated so that it contains no more
* than 'limit' elements.
*/
[Symbol.split](string: string, limit?: number): string[];
[Symbol.split](string: string, limit: 0): string[];
[Symbol.split](string: string, limit?: number): [string, ...string[]];
}

interface RegExpConstructor {
Expand Down Expand Up @@ -247,7 +248,8 @@ interface String {
* @param splitter An object that can split a string.
* @param limit A value used to limit the number of elements returned in the array.
*/
split(splitter: { [Symbol.split](string: string, limit?: number): string[]; }, limit?: number): string[];
split(splitter: { [Symbol.split](string: string, limit?: number): string[]; }, limit: 0): string[];
split(splitter: { [Symbol.split](string: string, limit?: number): string[]; }, limit?: number): [string, ...string[]];
}

interface ArrayBuffer {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ interface String {
* @param separator A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
* @param limit A value used to limit the number of elements returned in the array.
*/
split(separator: string | RegExp, limit?: number): string[];
split(separator: string | RegExp, limit: 0): string[];
split(separator: string | RegExp, limit?: number): [string, ...string[]];

/**
* Returns the substring at the specified location within a String object.
Expand Down