Repository navigation
Negated Types: Consider assertions invertible and create negated narrowings in false branches of assertion narrowings - #65296
Wesley Wigham (weswigham) wants to merge 24 commits into
Conversation
…t literal handling
Deduplicate fresh negations against their regular counterparts during union collection and intersection insertion. Preserve the first intersection position and ordered-set membership when replacing a fresh member, while leaving standalone fresh negations eligible for widening. Add compiler coverage for explicit exclusions, generic array narrowing, both union operand orders, and fresh-only widening.
…ntial structures, broaden negation reduction applicability
|
TypeScript Bot (@typescript-bot) test this |
|
Hey Wesley Wigham (@weswigham), this PR is in an unmergable state, so is missing a merge commit to run against; please resolve conflicts and try again. |
… branches of assertion narrowings
640c71d to
8db7e43
Compare
|
TypeScript Bot (@typescript-bot) test this |
|
Hey Wesley Wigham (@weswigham), the results of running the DT tests are ready. There were interesting changes: Branch only errors:
|
|
Wesley Wigham (@weswigham) Here are the results of running the user tests with tsc comparing Something interesting changed - please have a look. Details
|
|
Wesley Wigham (@weswigham), the perf run you requested failed. You can check the log here. |
|
TypeScript Bot (@typescript-bot) pack this |
|
Hey, Wesley Wigham (@weswigham)! I've packed 8db7e43 into an installable package. You can install it for testing by referencing it in your {
"devDependencies": {
"typescript": "npm:@typescript-deploys/pr-build@7.1.0-pr.65296.8"
}
}and then running There is also a playground for this build. |
|
Experiment done, work will continue in #64375 - this one might be followed up on in the future after negated types merge - it really wants new syntax to distinguish between invertible/partitioning type guards and not, which is not something we want to bundle into another new syntax proposal. |
Just like with conditionals, this isn't strictly sound to do. In particular, this trips over assertions which are less specific than the check they do.
For example,
isSimpleTypeReference(p: any): p is TypeReferencemakes total sense today, but if you narrow totypeof p & not TypeReferencein the false branch, you're just kinda wrong - it could still be a type reference (just not a "simple" one) - the specificity of the types and the implementation the guard checks don't match, and nothing actually forces them to - you could argue that it's even common for a type guard to produce a type less specific than what the guard actually checks, simply because that's the type that exists, and it didn't matter that it was overbroad before.