Skip to content

Commit 71f338b

Browse files
authored
Revert "typeRelatedToSomeType passes through intersectionState (microsoft#43707)" (microsoft#43983)
This reverts commit db09cb5.
1 parent a5607a4 commit 71f338b

File tree

5 files changed

+6
-236
lines changed

5 files changed

+6
-236
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17931,7 +17931,7 @@ namespace ts {
1793117931
let result = Ternary.True;
1793217932
const sourceTypes = source.types;
1793317933
for (const sourceType of sourceTypes) {
17934-
const related = typeRelatedToSomeType(sourceType, target, /*reportErrors*/ false, IntersectionState.None);
17934+
const related = typeRelatedToSomeType(sourceType, target, /*reportErrors*/ false);
1793517935
if (!related) {
1793617936
return Ternary.False;
1793717937
}
@@ -17940,29 +17940,29 @@ namespace ts {
1794017940
return result;
1794117941
}
1794217942

17943-
function typeRelatedToSomeType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean, intersectionState: IntersectionState): Ternary {
17943+
function typeRelatedToSomeType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean): Ternary {
1794417944
const targetTypes = target.types;
1794517945
if (target.flags & TypeFlags.Union) {
1794617946
if (containsType(targetTypes, source)) {
1794717947
return Ternary.True;
1794817948
}
1794917949
const match = getMatchingUnionConstituentForType(<UnionType>target, source);
1795017950
if (match) {
17951-
const related = isRelatedTo(source, match, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
17951+
const related = isRelatedTo(source, match, /*reportErrors*/ false);
1795217952
if (related) {
1795317953
return related;
1795417954
}
1795517955
}
1795617956
}
1795717957
for (const type of targetTypes) {
17958-
const related = isRelatedTo(source, type, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState);
17958+
const related = isRelatedTo(source, type, /*reportErrors*/ false);
1795917959
if (related) {
1796017960
return related;
1796117961
}
1796217962
}
1796317963
if (reportErrors) {
1796417964
const bestMatchingType = getBestMatchingType(source, target, isRelatedTo);
17965-
isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true, /*headMessage*/ undefined, intersectionState);
17965+
isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], /*reportErrors*/ true);
1796617966
}
1796717967
return Ternary.False;
1796817968
}
@@ -18222,7 +18222,7 @@ namespace ts {
1822218222
eachTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive), intersectionState & ~IntersectionState.UnionIntersectionCheck);
1822318223
}
1822418224
if (target.flags & TypeFlags.Union) {
18225-
return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), <UnionType>target, reportErrors && !(source.flags & TypeFlags.Primitive) && !(target.flags & TypeFlags.Primitive), intersectionState & ~IntersectionState.UnionIntersectionCheck);
18225+
return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), <UnionType>target, reportErrors && !(source.flags & TypeFlags.Primitive) && !(target.flags & TypeFlags.Primitive));
1822618226
}
1822718227
if (target.flags & TypeFlags.Intersection) {
1822818228
return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target as IntersectionType, reportErrors, IntersectionState.Target);

tests/baselines/reference/recursiveExcessPropertyChecks.js

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,59 +12,12 @@ function getMaxId(items: NodeWithId[]) {
1212

1313
const nodes = [] as ITreeItem[];
1414
getMaxId(nodes);
15-
16-
17-
// Repro from #42715
18-
export interface Donkey {
19-
donkey: string;
20-
}
21-
22-
interface Diddy {
23-
diddy: string;
24-
children?: Diddy[] | Donkey;
25-
}
26-
27-
interface Cranky {
28-
cranky: string;
29-
children: Diddy;
30-
}
31-
32-
type Dandy = Diddy & {
33-
children: (Diddy & { funky?: string })[];
34-
};
35-
type X = Dandy["children"]
36-
var x: X
37-
38-
const mainView: Dandy = {
39-
diddy: "",
40-
children: [
41-
{
42-
diddy: "",
43-
funky: "Empty" // <- Incorrect error
44-
}
45-
],
46-
};
47-
// Legal
48-
const p = mainView.children[0].funky
4915

5016

5117
//// [recursiveExcessPropertyChecks.js]
5218
"use strict";
5319
// Repro from #35804
54-
exports.__esModule = true;
5520
function getMaxId(items) {
5621
}
5722
var nodes = [];
5823
getMaxId(nodes);
59-
var x;
60-
var mainView = {
61-
diddy: "",
62-
children: [
63-
{
64-
diddy: "",
65-
funky: "Empty" // <- Incorrect error
66-
}
67-
]
68-
};
69-
// Legal
70-
var p = mainView.children[0].funky;

tests/baselines/reference/recursiveExcessPropertyChecks.symbols

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -27,80 +27,3 @@ getMaxId(nodes);
2727
>getMaxId : Symbol(getMaxId, Decl(recursiveExcessPropertyChecks.ts, 6, 46))
2828
>nodes : Symbol(nodes, Decl(recursiveExcessPropertyChecks.ts, 11, 5))
2929

30-
31-
// Repro from #42715
32-
export interface Donkey {
33-
>Donkey : Symbol(Donkey, Decl(recursiveExcessPropertyChecks.ts, 12, 16))
34-
35-
donkey: string;
36-
>donkey : Symbol(Donkey.donkey, Decl(recursiveExcessPropertyChecks.ts, 16, 25))
37-
}
38-
39-
interface Diddy {
40-
>Diddy : Symbol(Diddy, Decl(recursiveExcessPropertyChecks.ts, 18, 1))
41-
42-
diddy: string;
43-
>diddy : Symbol(Diddy.diddy, Decl(recursiveExcessPropertyChecks.ts, 20, 17))
44-
45-
children?: Diddy[] | Donkey;
46-
>children : Symbol(Diddy.children, Decl(recursiveExcessPropertyChecks.ts, 21, 18))
47-
>Diddy : Symbol(Diddy, Decl(recursiveExcessPropertyChecks.ts, 18, 1))
48-
>Donkey : Symbol(Donkey, Decl(recursiveExcessPropertyChecks.ts, 12, 16))
49-
}
50-
51-
interface Cranky {
52-
>Cranky : Symbol(Cranky, Decl(recursiveExcessPropertyChecks.ts, 23, 1))
53-
54-
cranky: string;
55-
>cranky : Symbol(Cranky.cranky, Decl(recursiveExcessPropertyChecks.ts, 25, 18))
56-
57-
children: Diddy;
58-
>children : Symbol(Cranky.children, Decl(recursiveExcessPropertyChecks.ts, 26, 19))
59-
>Diddy : Symbol(Diddy, Decl(recursiveExcessPropertyChecks.ts, 18, 1))
60-
}
61-
62-
type Dandy = Diddy & {
63-
>Dandy : Symbol(Dandy, Decl(recursiveExcessPropertyChecks.ts, 28, 1))
64-
>Diddy : Symbol(Diddy, Decl(recursiveExcessPropertyChecks.ts, 18, 1))
65-
66-
children: (Diddy & { funky?: string })[];
67-
>children : Symbol(children, Decl(recursiveExcessPropertyChecks.ts, 30, 22))
68-
>Diddy : Symbol(Diddy, Decl(recursiveExcessPropertyChecks.ts, 18, 1))
69-
>funky : Symbol(funky, Decl(recursiveExcessPropertyChecks.ts, 31, 24))
70-
71-
};
72-
type X = Dandy["children"]
73-
>X : Symbol(X, Decl(recursiveExcessPropertyChecks.ts, 32, 2))
74-
>Dandy : Symbol(Dandy, Decl(recursiveExcessPropertyChecks.ts, 28, 1))
75-
76-
var x: X
77-
>x : Symbol(x, Decl(recursiveExcessPropertyChecks.ts, 34, 3))
78-
>X : Symbol(X, Decl(recursiveExcessPropertyChecks.ts, 32, 2))
79-
80-
const mainView: Dandy = {
81-
>mainView : Symbol(mainView, Decl(recursiveExcessPropertyChecks.ts, 36, 5))
82-
>Dandy : Symbol(Dandy, Decl(recursiveExcessPropertyChecks.ts, 28, 1))
83-
84-
diddy: "",
85-
>diddy : Symbol(diddy, Decl(recursiveExcessPropertyChecks.ts, 36, 25))
86-
87-
children: [
88-
>children : Symbol(children, Decl(recursiveExcessPropertyChecks.ts, 37, 14))
89-
{
90-
diddy: "",
91-
>diddy : Symbol(diddy, Decl(recursiveExcessPropertyChecks.ts, 39, 9))
92-
93-
funky: "Empty" // <- Incorrect error
94-
>funky : Symbol(funky, Decl(recursiveExcessPropertyChecks.ts, 40, 22))
95-
}
96-
],
97-
};
98-
// Legal
99-
const p = mainView.children[0].funky
100-
>p : Symbol(p, Decl(recursiveExcessPropertyChecks.ts, 46, 5))
101-
>mainView.children[0].funky : Symbol(funky, Decl(recursiveExcessPropertyChecks.ts, 31, 24))
102-
>mainView.children : Symbol(children, Decl(recursiveExcessPropertyChecks.ts, 21, 18), Decl(recursiveExcessPropertyChecks.ts, 30, 22))
103-
>mainView : Symbol(mainView, Decl(recursiveExcessPropertyChecks.ts, 36, 5))
104-
>children : Symbol(children, Decl(recursiveExcessPropertyChecks.ts, 21, 18), Decl(recursiveExcessPropertyChecks.ts, 30, 22))
105-
>funky : Symbol(funky, Decl(recursiveExcessPropertyChecks.ts, 31, 24))
106-

tests/baselines/reference/recursiveExcessPropertyChecks.types

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -25,75 +25,3 @@ getMaxId(nodes);
2525
>getMaxId : (items: NodeWithId[]) => void
2626
>nodes : ITreeItem[]
2727

28-
29-
// Repro from #42715
30-
export interface Donkey {
31-
donkey: string;
32-
>donkey : string
33-
}
34-
35-
interface Diddy {
36-
diddy: string;
37-
>diddy : string
38-
39-
children?: Diddy[] | Donkey;
40-
>children : Donkey | Diddy[] | undefined
41-
}
42-
43-
interface Cranky {
44-
cranky: string;
45-
>cranky : string
46-
47-
children: Diddy;
48-
>children : Diddy
49-
}
50-
51-
type Dandy = Diddy & {
52-
>Dandy : Dandy
53-
54-
children: (Diddy & { funky?: string })[];
55-
>children : (Diddy & { funky?: string | undefined; })[]
56-
>funky : string | undefined
57-
58-
};
59-
type X = Dandy["children"]
60-
>X : (Donkey | Diddy[] | undefined) & (Diddy & { funky?: string | undefined; })[]
61-
62-
var x: X
63-
>x : (Donkey | Diddy[] | undefined) & (Diddy & { funky?: string | undefined; })[]
64-
65-
const mainView: Dandy = {
66-
>mainView : Dandy
67-
>{ diddy: "", children: [ { diddy: "", funky: "Empty" // <- Incorrect error } ],} : { diddy: string; children: { diddy: string; funky: string; }[]; }
68-
69-
diddy: "",
70-
>diddy : string
71-
>"" : ""
72-
73-
children: [
74-
>children : { diddy: string; funky: string; }[]
75-
>[ { diddy: "", funky: "Empty" // <- Incorrect error } ] : { diddy: string; funky: string; }[]
76-
{
77-
>{ diddy: "", funky: "Empty" // <- Incorrect error } : { diddy: string; funky: string; }
78-
79-
diddy: "",
80-
>diddy : string
81-
>"" : ""
82-
83-
funky: "Empty" // <- Incorrect error
84-
>funky : string
85-
>"Empty" : "Empty"
86-
}
87-
],
88-
};
89-
// Legal
90-
const p = mainView.children[0].funky
91-
>p : string | undefined
92-
>mainView.children[0].funky : string | undefined
93-
>mainView.children[0] : Diddy & { funky?: string | undefined; }
94-
>mainView.children : (Donkey | Diddy[] | undefined) & (Diddy & { funky?: string | undefined; })[]
95-
>mainView : Dandy
96-
>children : (Donkey | Diddy[] | undefined) & (Diddy & { funky?: string | undefined; })[]
97-
>0 : 0
98-
>funky : string | undefined
99-

tests/cases/compiler/recursiveExcessPropertyChecks.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,3 @@ function getMaxId(items: NodeWithId[]) {
1313

1414
const nodes = [] as ITreeItem[];
1515
getMaxId(nodes);
16-
17-
18-
// Repro from #42715
19-
export interface Donkey {
20-
donkey: string;
21-
}
22-
23-
interface Diddy {
24-
diddy: string;
25-
children?: Diddy[] | Donkey;
26-
}
27-
28-
interface Cranky {
29-
cranky: string;
30-
children: Diddy;
31-
}
32-
33-
type Dandy = Diddy & {
34-
children: (Diddy & { funky?: string })[];
35-
};
36-
type X = Dandy["children"]
37-
var x: X
38-
39-
const mainView: Dandy = {
40-
diddy: "",
41-
children: [
42-
{
43-
diddy: "",
44-
funky: "Empty" // <- Incorrect error
45-
}
46-
],
47-
};
48-
// Legal
49-
const p = mainView.children[0].funky

0 commit comments

Comments
 (0)