-
Notifications
You must be signed in to change notification settings - Fork 89
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
feat: Improve startsWith
, includes
and endsWith
typings for TS 4.5
#622
Conversation
@@ -1013,8 +1013,8 @@ Notes: | |||
|
|||
*/ | |||
// @SINGLE_MARKER | |||
export function endsWith(target: string, iterable: string): boolean; | |||
export function endsWith(target: string): (iterable: string) => boolean; | |||
export function endsWith<T extends string>(target: T, str: string): str is `${string}${T}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed second arg from iterable
to str
to match startsWith
method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we also need to change description of these methods from iterable
to something else (input
?)
will take a look at it, but there is linting enabled, but it is missing in CONTRIBUTING.md and it will be updated. |
startsWith
, includes
and endsWith
typings for for TS 4.5startsWith
, includes
and endsWith
typings for TS 4.5
startsWith
, includes
and endsWith
typings for TS 4.5startsWith
, includes
and endsWith
typings for TS 4.5
FIrst, I want to say sorry for my late reply. Second, I see few issues arising from this MR:
|
ok, I see in:
the actual value of this MR, but what about the
This is very new TS feature and I believe that TS team will build upon it. Then the value of your suggested change might increase, but currently I am inclined towards closing this MR. Let me know your thoughts on the matter. |
One more note. Such typings:
gives us |
By the way, are you sure that minimum supported TS version should be raised only because of this change? Though I didn't test it with previous versions.
Oh wow, this is pretty interesting, I'm gonna look into it tomorrow. But for now, if you think this is too early to add here, I'm fine with closing this PR. I believe we could reopen it some day (if this is really problem with just TS). |
There is a test in |
I am merging this and it will be released with 8.0 |
Actually, I cannot make typing test give me proper result, so I will decline it. If you provide typing test for this, I am willing to approve it. |
There might be a better title for this PR.
Starting from TypeScript 4.5 strings can be narrowed:
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#template-string-types-as-discriminants
Also see microsoft/TypeScript#46137 (comment)
Should I do the same in
@types/ramda
as well?Also I noticed absence of formatter. Don't you mind enabling something like Prettier?