-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Fix issues + Support template literal types as discriminants #46137
Conversation
|
||
// Repro from #46045 | ||
|
||
export type Action = |
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.
We probably want to remove the export
from this and the other line to keep around the declaration emit in the test.
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.
Yeah, for sure.
const targetEnd = target.texts[target.texts.length - 1]; | ||
const startLen = Math.min(sourceStart.length, targetStart.length); | ||
const endLen = Math.min(sourceEnd.length, targetEnd.length); | ||
return sourceStart.slice(0, startLen) !== targetStart.slice(0, startLen) || |
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.
Won't this flag foo-${boolean}
and foo-${number}
as possibly related? We still need to make sure the holes relate when this returns True
, no?
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.
Yes, it'll flag them as possibly related. Or, rather, not flag them as definitely unrelated. We could potentially check the placeholders that immediately follow identical prefix texts or immediately precede identical suffix texts, but honestly there's very little gained from it. In fact, probably only the boolean
vs. number
disqualification. I think what is here already is sufficient, and it impacts whether we flag operands as non-overlapping, which isn't super critical to get 100% right.
|
||
// Repro from #46125 | ||
|
||
function ff1<T extends string>(x: `foo-${string}`, y: `${string}-bar`, z: `baz-${string}`) { |
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.
Before I forget, can we also get a copy of this test with a signature like
function ff1<T extends string>(x: `foo-${T}`, y: `${T}-bar`, z: `baz-${T}`) {
? I figure it should behave the same, but, y'know, coverage. Maybe it can just be more cases on this signature, since it already has a generic parameter for some reason~
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.
Will do.
@typescript-bot test this |
Heya @DanielRosenwasser, I've started to run the perf test suite on this PR at e1907a2. You can monitor the build here. Update: The results are in! |
Heya @DanielRosenwasser, I've started to run the extended test suite on this PR at e1907a2. You can monitor the build here. |
Heya @DanielRosenwasser, I've started to run the parallelized community code test suite on this PR at e1907a2. You can monitor the build here. |
@DanielRosenwasser Here they are:Comparison Report - main..46137
System
Hosts
Scenarios
Developer Information: |
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
Tests look clean, perf is slightly improved if anything. I think this one is good to go! |
Great! But will buitin string methods support this? For now, I'm forced to use these standalone functions: const startsWith = <T extends string>(str: string, search: T): str is `${T}${string}` => str.startsWith(search);
const endsWith = <T extends string>(str: string, search: T): str is `${string}${T}` => str.endsWith(search);
const includes = <T extends string>(str: string, search: T): str is `${string}${T}${string}` => str.includes(search); |
Fixes #46045.
Fixes #46125.