Skip to content
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

Improve intersection reduction and CFA for truthy, equality, and typeof checks #49119

Merged
merged 32 commits into from
May 27, 2022
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ce23b8d
Improve reduction of intersection types
ahejlsberg May 5, 2022
ffe147e
Accept new baselines
ahejlsberg May 5, 2022
a95de48
Merge branch 'main' into improveIntersectionReduction
ahejlsberg May 13, 2022
29edef1
Improve CFA for truthy, equality, and typeof checks
ahejlsberg May 15, 2022
39326d7
Accept new baselines
ahejlsberg May 15, 2022
d0b7ec8
Remove special case for Function type
ahejlsberg May 15, 2022
a25388d
Merge branch 'main' into improveIntersectionReduction
ahejlsberg May 15, 2022
95c3c56
Don't reduce intersections of form {...} & object
ahejlsberg May 15, 2022
986963c
Accept new baselines
ahejlsberg May 15, 2022
c400181
Anything is assignable to unknown-like union
ahejlsberg May 16, 2022
f1ebcdd
Accept new baselines
ahejlsberg May 16, 2022
73c91fd
Tweak subtype check
ahejlsberg May 16, 2022
722c462
Recombine unknown type from unknown-like union in more cases
ahejlsberg May 17, 2022
5e1111a
Display union origin only if it is shorter than union itself
ahejlsberg May 18, 2022
5c579a4
Accept new baselines
ahejlsberg May 18, 2022
8913cf0
Add tests
ahejlsberg May 18, 2022
dbce210
Only attach origin type when it is shorter than union itself
ahejlsberg May 19, 2022
1913c94
Specially preserve string & {}, number & {}, bigint & {}
ahejlsberg May 20, 2022
8c7a38b
Accept new baselines
ahejlsberg May 20, 2022
6f18e90
Add additional tests
ahejlsberg May 20, 2022
e70bf7c
Fix getNormalizedType and getNarrowableTypeForReference for intersect…
ahejlsberg May 20, 2022
7a62983
Switch NonNullable<T> to use T & {}
ahejlsberg May 20, 2022
c35cba7
Accept new baselines
ahejlsberg May 20, 2022
a0c0929
Use NonNullable<T> in place of anonymous T & {}
ahejlsberg May 20, 2022
eff3be3
Accept new baselines
ahejlsberg May 20, 2022
d3eb84f
Add fourslash test
ahejlsberg May 24, 2022
954e80a
More fourslash tests
ahejlsberg May 24, 2022
1d9b53f
Fix getFalsyFlags handling of intersections
ahejlsberg May 26, 2022
3815934
Accept new baselines
ahejlsberg May 26, 2022
bfa3a90
Add constraint to compareProperties type parameter
ahejlsberg May 26, 2022
9801667
Unconstrained type parameter not assignable to {} with strictNullChecks
ahejlsberg May 26, 2022
51da289
Accept new baselines
ahejlsberg May 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't reduce intersections of form {...} & object
  • Loading branch information
ahejlsberg committed May 15, 2022
commit 95c3c565602bcc3984c190a5863444c2927e925a
7 changes: 4 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14838,7 +14838,6 @@ namespace ts {
t.flags & TypeFlags.BigInt && includes & TypeFlags.BigIntLiteral ||
t.flags & TypeFlags.ESSymbol && includes & TypeFlags.UniqueESSymbol ||
t.flags & TypeFlags.Void && includes & TypeFlags.Undefined ||
t.flags & TypeFlags.NonPrimitive && includes & TypeFlags.Object ||
isEmptyAnonymousObjectType(t) && includes & TypeFlags.DefinitelyNonNullable;
if (remove) {
orderedRemoveItemAt(types, i);
Expand Down Expand Up @@ -15002,7 +15001,6 @@ namespace ts {
includes & TypeFlags.BigInt && includes & TypeFlags.BigIntLiteral ||
includes & TypeFlags.ESSymbol && includes & TypeFlags.UniqueESSymbol ||
includes & TypeFlags.Void && includes & TypeFlags.Undefined ||
includes & TypeFlags.NonPrimitive && includes & TypeFlags.Object ||
includes & TypeFlags.IncludesEmptyObject && includes & TypeFlags.DefinitelyNonNullable) {
removeRedundantSupertypes(typeSet, includes);
}
Expand Down Expand Up @@ -25061,9 +25059,12 @@ namespace ts {
if (!areTypesComparable(t, c)) {
return neverType;
}
if ((c.flags & TypeFlags.Primitive) && t.flags & TypeFlags.Object && !isEmptyAnonymousObjectType(t)) {
if (c.flags & TypeFlags.Primitive && t.flags & TypeFlags.Object && !isEmptyAnonymousObjectType(t)) {
return isTypeSubtypeOf(c, t) ? c : neverType;
}
if (c === globalFunctionType && t.flags & TypeFlags.NonPrimitive) {
return c;
}
return getIntersectionType([t, c]);
});
});
Expand Down