-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
modify String.split and Array.pop to fix a non-bug(!?) in top-repos pubkey/rxdb #56323
Comments
The type of
|
You changed it to:
This will only work for the string literal |
I closed this issue, but then on second thoughts I open it again. That because use of "" as a separator has a different semantics from a separator which is not empty - it splits the string into length 1 character strings. Therefore, generally speaking, your linked example would not use a variable that could possibly be the empty string. Conversely, when the semantic behavior desired is exactly to split the string into characters, it will generally always use the string literal. I'd bet greater than even odds the modification could be made without triggering runtime regressions. |
Tuples have length with a literal number. |
But approximately no one calls |
Bold assumption you make for a suggested change to the standard library types. |
This proposal has some problems - I'm going to close it. The motivation, however, remains. |
🔍 Search Terms
#52299 (closed)
#30406 (marked as design limitation)
"typescript issues Literal String should have literal length"
Turned up #52243 and #41160
but those are both more complicated proposals with string ranges.
This proposal only considers plain string literal, for which implementing literal length would straightforward.
✅ Viability Checklist
⭐ Suggestion
before:
after:
📃 Motivating Example
In the source of submitting another pull, this error occurred in the bot driver top-repos job
which maybe means it was already an error, and which can be reproduced in 5.2.2 with
💻 Use Cases
Eliminating a top-repos non-bug (Non-bug because it is not expected to compile in 5.2.2),
and to address previous issues which were closed without considering the solution proposed here.
Using "String.split" with a non zero length literal string is a common case that case a narrower type is correct.
Additionally, "Array.pop" is sometimes used on tuples with length >0 , and in that case
a narrower type is correct.
They may be used in conjunction as shown.
The goal is a better user experience.
No reasonable workaround is possible unless string literals are given specific length
in the same way that tuples are.
The text was updated successfully, but these errors were encountered: