Description
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(' ')
or split('\n')
Configuration Check
My compilation target is ES2015
and my lib is the default
.
Missing / Incorrect Definition
Line 460 in b70784e
Essentially duplicate of #49635, but with #49635 (comment) handled:
split<T extends string | RegExp>(separator: T, limit?: number): T extends `${string}${infer U}` ? [string, ...string[]] : string[];
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:
const [firstLine, ...restLine] = str.split('\n')
// firstLine is possibly undefined, need add exclamation marks everywhere or `as [string, ...string]` above
I also wanted to do the same for when regexp literal is passed e.g. split(/\n\r?/)
as only split(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 anyway
Documentation Link
P.S. I remembered of this issue after #49682, which significantly improved type-checking experience by using less exclamation marks