Improve string split return type of first array index #53362
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
lib Update Request
Please, consider improving user experience for
"".split(...)
in cases when string literal is passed, which I believe most users do e.g.split(' ')
orsplit('\n')
Configuration Check
My compilation target is
ES2015
and my lib isthe default
.Missing / Incorrect Definition
TypeScript/src/lib/es5.d.ts
Line 460 in b70784e
Essentially duplicate of #49635, but with #49635 (comment) handled:
And this should added to param JSDoc then:
Only passing `""` and `new RegExp("")` values can result in returning an empty array.
Sample Code
This is super inconvenient when used with destructure:
I also wanted to do the same for when regexp literal is passed e.g.
split(/\n\r?/)
as onlysplit(new RegExp(''))
can result in empty array (if I'm not mistaken), which I believe no one does, but the literal value can't be captured anywayDocumentation Link
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split#description (note)
P.S. I remembered of this issue after #49682, which significantly improved type-checking experience by using less exclamation marks
The text was updated successfully, but these errors were encountered: