| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…an optional chain
| return narrowTypeByConstructor(type, operator, left, assumeTrue); | ||
| } | ||
| if (isBooleanLiteral(right)) { | ||
| if (isBooleanLiteral(right) && !isAccessExpression(left)) { |
There was a problem hiding this comment.
It turns out that the original type can be reassigned based on optionalChainContainsReference. That messed up the else branch because narrowTypeByBooleanComparison was operating on the wrong type.
I've also tried keeping originalType around and pass that to narrowTypeByBooleanComparison. That fixed the reported issue~ related to the wrong type in the else branch but it broke the same type within the if block. This happened because originally the intention was for that reassigned type to be returned through the return at the bottom of this function but I changed it to return originalType through narrowTypeByBooleanComparison.
So all in all, this seems like the simplest fix and reflects the intention the best. The motivation behind the original change was to improve non-access expression narrowing. Access expressions are already handled by discrimination-based narrowing etc.
Even though it worked previously (as far as I know) for non-optional chain access expressions, this helps them avoid some redundant work too.
Sorry, something went wrong.
There was a problem hiding this comment.
This seems fine as a quick fix for now, though I suspect that we could try and do better later.
Sorry, something went wrong.
There was a problem hiding this comment.
Then again, not sure what "better" even means; an expression like (options?.a === false || options.b is not the same as (!options?.a || options.b) so realistically I don't think there's any extra info gained here.
Sorry, something went wrong.
|
TypeScript Bot (@typescript-bot) test top200 TypeScript Bot (@typescript-bot) perf test this |
Sorry, something went wrong.
|
Heya Jake Bailey (@jakebailey), I've started to run the parallelized Definitely Typed test suite on this PR at b549581. You can monitor the build here. Update: The results are in! |
Sorry, something went wrong.
|
Heya Jake Bailey (@jakebailey), I've started to run the tarball bundle task on this PR at b549581. You can monitor the build here. |
Sorry, something went wrong.
|
Heya Jake Bailey (@jakebailey), I've started to run the diff-based user code test suite on this PR at b549581. You can monitor the build here. Update: The results are in! |
Sorry, something went wrong.
|
Heya Jake Bailey (@jakebailey), I've started to run the diff-based top-repos suite on this PR at b549581. You can monitor the build here. Update: The results are in! |
Sorry, something went wrong.
|
Heya Jake Bailey (@jakebailey), I've started to run the regular perf test suite on this PR at b549581. You can monitor the build here. Update: The results are in! |
Sorry, something went wrong.
|
Hey Jake Bailey (@jakebailey), I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so: {
"devDependencies": {
"typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/158776/artifacts?artifactName=tgz&fileId=0354B9F2A4021077377EA088E6459FA61983E3E2334251E88120F6D99779965F02&fileName=/typescript-5.4.0-insiders.20231122.tgz"
}
}
and then running npm install. There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@5.4.0-pr-56504-6".; |
Sorry, something went wrong.
|
Jake Bailey (@jakebailey) Here are the results of running the user test suite comparing main and refs/pull/56504/merge: There were infrastructure failures potentially unrelated to your change:
Otherwise... Something interesting changed - please have a look. Detailspuppeteerpackages/browsers/test/src/tsconfig.json
|
Sorry, something went wrong.
|
Jake Bailey (@jakebailey)
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
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sorry, something went wrong.
|
Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready. |
Sorry, something went wrong.
|
Jake Bailey (@jakebailey) Here are the results of running the top-repos suite comparing main and refs/pull/56504/merge: Everything looks good! |
Sorry, something went wrong.
| return narrowTypeByConstructor(type, operator, left, assumeTrue); | ||
| } | ||
| if (isBooleanLiteral(right)) { | ||
| if (isBooleanLiteral(right) && !isAccessExpression(left)) { |
There was a problem hiding this comment.
This seems fine as a quick fix for now, though I suspect that we could try and do better later.
Sorry, something went wrong.
|
TypeScript Bot (@typescript-bot) cherry-pick this to release-5.3 |
Sorry, something went wrong.
|
Heya Jake Bailey (@jakebailey), I've started to cherry-pick this into release-5.3 for you. Here's the link to my best guess at the log. |
Sorry, something went wrong.
|
Hey Jake Bailey (@jakebailey), I was unable to cherry-pick this PR. Check the logs at: https://github.com/microsoft/TypeScript/actions/runs/6961303591 |
Sorry, something went wrong.
|
TypeScript Bot (@typescript-bot) cherry-pick this to release-5.3 |
Sorry, something went wrong.
|
Heya Jake Bailey (@jakebailey), I've started to cherry-pick this into release-5.3 for you. Here's the link to my best guess at the log. |
Sorry, something went wrong.
|
Hey Jake Bailey (@jakebailey), I was unable to cherry-pick this PR. Check the logs at: https://github.com/microsoft/TypeScript/actions/runs/6961580628 |
Sorry, something went wrong.
|
TypeScript Bot (@typescript-bot) cherry-pick this to release-5.3 |
Sorry, something went wrong.
|
Heya Jake Bailey (@jakebailey), I've started to cherry-pick this into release-5.3 for you. Here's the link to my best guess at the log. |
Sorry, something went wrong.
|
Hey Jake Bailey (@jakebailey), I've created #56512 for you. |
Sorry, something went wrong.
|
Is using isAccessExpression just intended to not check more deeply on the expression? |
Sorry, something went wrong.
|
Never mind, I think I understand now. |
Sorry, something went wrong.
If you write an expression like options?.a === false || options.b or options?.a === undefined || options.b, it's not the same as like !options?.a || options.b; specifically, it doesn't provide any information about whether the equality was done on options or options.a, so we can't know if options was undefined or not for the following expression. Kinda makes sense; we're allowing a narrowing based on a specific falsy value. It's possible that this could work with just ==, though, but I think the big hammer is okay. |
Sorry, something went wrong.
…to release-5.3 (microsoft#56512) Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
| Back | FazBrowse Home | New Git URL |
fixes #56482
cc Jake Bailey (@jakebailey)