feat(core): resolve nested type qualifiers + improve type/value duality handling #6143
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements 2 major improvements that are especially important in interpreting
.d.tsfiles (but may benefit other code too), and has some minor improvements too.Nested type qualifiers can be resolved
For instance, the following will now resolve correctly:
Type/value duality is correctly handled
A new
TypeData::DualReferencevariant has been introduced that can simultaneously reference a type, as well as the type of a value.Dual types can even be exported and imported too.
I also discovered the tests for
useExhaustiveSwitchCasescontained some cases that used to have incorrect results because of this duality, which are now fixed too. cc @siketyanImproved operator inference
Inference has improved for a few operators, especially the
typeofoperator, but also other unary operators such as unary minus (-) and bitwise not (~).Reordered global type IDs in snapshots
Global type IDs are always a bit confusing in snapshots, because we have predefined global types that we don't wish to be part of the snapshots. This meant global type IDs would always start counting from a seemingly arbitrary index, such as 17. Now they always start at 0, which should also help to make snapshots change less going forward. The downside is that for global type IDs, the numbers in the snapshots no longer match the internal type IDs.
Test Plan
Test cases added and snapshots updated.