-
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
Bail early in getNarrowedTypeWorker if type is candidate #55926
Conversation
@typescript-bot perf test this |
Heya @jakebailey, I've started to run the regular perf test suite on this PR at b330fbc. You can monitor the build here. Update: The results are in! |
Heya @jakebailey, I've started to run the tarball bundle task on this PR at b330fbc. You can monitor the build here. |
Hey @jakebailey, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build and an npm module you can use via |
@jakebailey Here they are:
CompilerComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
tsserverComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
StartupComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@typescript-bot perf test this faster |
Heya @jakebailey, I've started to run the tsc-only perf test suite on this PR at 1c14f5c. You can monitor the build here. Update: The results are in! |
@jakebailey Here they are:
CompilerComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
I still feel like this might be slightly silly, but it seems really cheap and quick to just check for cases where we're trying to narrow something to itself and bail early without doing all of the other work. |
The change makes sense, but where in type checking the motivating case https://github.com/epmatsw/tsdemo/blob/main/slow.ts do we call |
I think the example has been updated; it used to be narrowing something to itself. |
Do you have an example then? |
The repro repo has it if you go back a few commits: https://github.com/epmatsw/tsdemo/tree/b2a2af937e492819045ea4e880a56236494c2147 Something like: function test(base: SpecificString) {
if (isSpecificString(base)) {
return base;
}
} Where |
Ah, so it is an explicit narrowing to itself. I don't know how common it is, it doesn't seem like something you want to be doing, but then again you might be programming defensively and you want to validate at run time that something has a type, so I can see a case for writing this kind of code. |
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.
Don't know if you're still waiting on my review for this, but this can be a reminder to merge this at some point~
I was, kinda; mainly I was trying to decide if this was even worthwhile if it's so rare and silly. |
This technically handles #52345 (comment) and maybe #55948, bringing it back to <=4.7 levels, but I think it's a little silly to narrow something to itself. But, probably cheap to check anyhow.