microsoft / microsoft/TypeScript
String.split() method's separator argument should allow undefined
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
### ⚙ 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
```TypeScript
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
Contributor guide
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.
Assessment
- Tech stack
- javascript, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100