String.split() method's separator argument should allow undefined

Open Beginner friendly
#63,456 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Domain
tooling

Research direction

Review the String.split declaration against the linked ECMAScript specification, focusing on the separator argument and the provided sample. Done means the TypeScript definition accepts undefined and the sample type-checks without requiring a separate code path.

Written by the indexing model from the issue text.

Description

Awaiting More Feedback Suggestion
⚙ Compilation target

ES2024

⚙ Library

6.0.2

Missing / Incorrect Definition

String.split should allow undefined as its separator argument, resulting in an array containing the entire string.

Unlike the case of omitting the separator (#38331), this is a useful feature, since separator may be a variable, and it can be desirable to get an array with the entire string in the case that separator is not set, in order to not need a different code path for this case.

This feature is explicitly defined in the spec. It is not something that just 'happens to work', like using null or a number.

Sample Code
console.log("string,that could/split:but-should;not".split(undefined));
Documentation Link

https://tc39.es/ecma262/multipage/text-processing.html#sec-string.prototype.split

Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 15h
Merged PRs (30d)
106

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/TypeScript

All issues in microsoft/TypeScript

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.