diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3d4f288f1293b..6272723424966 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11979,7 +11979,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (!links.writeType && links.deferralWriteConstituents) { Debug.assertIsDefined(links.deferralParent); Debug.assertIsDefined(links.deferralConstituents); - links.writeType = links.deferralParent.flags & TypeFlags.Union ? getUnionType(links.deferralWriteConstituents) : getIntersectionType(links.deferralWriteConstituents); + links.writeType = links.deferralParent.flags & TypeFlags.Union ? getIntersectionType(links.deferralWriteConstituents) : getUnionType(links.deferralWriteConstituents); } return links.writeType; } @@ -14674,7 +14674,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else { result.links.type = isUnion ? getUnionType(propTypes) : getIntersectionType(propTypes); if (writeTypes) { - result.links.writeType = isUnion ? getUnionType(writeTypes) : getIntersectionType(writeTypes); + result.links.writeType = isUnion ? getIntersectionType(writeTypes) : getUnionType(writeTypes); } } return result; diff --git a/tests/baselines/reference/divergentAccessorsTypes-56894-a.js b/tests/baselines/reference/divergentAccessorsTypes-56894-a.js new file mode 100644 index 0000000000000..533f92a2d0892 --- /dev/null +++ b/tests/baselines/reference/divergentAccessorsTypes-56894-a.js @@ -0,0 +1,64 @@ +//// [tests/cases/compiler/-da/divergentAccessorsTypes-56894-a.ts] //// + +//// [divergentAccessorsTypes-56894-a.ts] +declare const id:()=>T + +function f2(x: {f:((a:1|2)=>1|2)} | {f:((a:2|3)=>2|3)} ){ + const r = x.f(id()) +// ^ const id: <2>() => 2, +// ^ const r: 1 | 2 | 3 +} + +function f3(f: ((a:1|2)=>1|2) | ((a:2|3)=>2|3) ){ + const r = f(id()) +// ^ const id: <2>() => 2, +// ^ const r: 1 | 2 | 3 +} + + +function f4(x: {set d(a:1|2); get r():1|2} | {set d(a:2|3); get r():2|3} ){ +// ^ (parameter) x: { d: 1 | 2; readonly r: 1 | 2; } | { d: 2 | 3; readonly r: 2 | 3; } + x.d = id(); +// ^ const id: <1 | 2 | 3>() => 1 | 2 | 3 (5.3.2) +// ^ const id: <2>() => 2 (expecting, if a setter was treated as a function) + x.r; +// ^ (property) r: 1 | 2 | 3 +} + +//// [divergentAccessorsTypes-56894-a.js] +"use strict"; +function f2(x) { + const r = x.f(id()); + // ^ const id: <2>() => 2, + // ^ const r: 1 | 2 | 3 +} +function f3(f) { + const r = f(id()); + // ^ const id: <2>() => 2, + // ^ const r: 1 | 2 | 3 +} +function f4(x) { + // ^ (parameter) x: { d: 1 | 2; readonly r: 1 | 2; } | { d: 2 | 3; readonly r: 2 | 3; } + x.d = id(); + // ^ const id: <1 | 2 | 3>() => 1 | 2 | 3 (5.3.2) + // ^ const id: <2>() => 2 (expecting, if a setter was treated as a function) + x.r; + // ^ (property) r: 1 | 2 | 3 +} + + +//// [divergentAccessorsTypes-56894-a.d.ts] +declare const id: () => T; +declare function f2(x: { + f: ((a: 1 | 2) => 1 | 2); +} | { + f: ((a: 2 | 3) => 2 | 3); +}): void; +declare function f3(f: ((a: 1 | 2) => 1 | 2) | ((a: 2 | 3) => 2 | 3)): void; +declare function f4(x: { + set d(a: 1 | 2); + get r(): 1 | 2; +} | { + set d(a: 2 | 3); + get r(): 2 | 3; +}): void; diff --git a/tests/baselines/reference/divergentAccessorsTypes-56894-a.symbols b/tests/baselines/reference/divergentAccessorsTypes-56894-a.symbols new file mode 100644 index 0000000000000..b729671d78c7d --- /dev/null +++ b/tests/baselines/reference/divergentAccessorsTypes-56894-a.symbols @@ -0,0 +1,69 @@ +//// [tests/cases/compiler/-da/divergentAccessorsTypes-56894-a.ts] //// + +=== divergentAccessorsTypes-56894-a.ts === +declare const id:()=>T +>id : Symbol(id, Decl(divergentAccessorsTypes-56894-a.ts, 0, 13)) +>T : Symbol(T, Decl(divergentAccessorsTypes-56894-a.ts, 0, 18)) +>T : Symbol(T, Decl(divergentAccessorsTypes-56894-a.ts, 0, 18)) + +function f2(x: {f:((a:1|2)=>1|2)} | {f:((a:2|3)=>2|3)} ){ +>f2 : Symbol(f2, Decl(divergentAccessorsTypes-56894-a.ts, 0, 25)) +>x : Symbol(x, Decl(divergentAccessorsTypes-56894-a.ts, 2, 12)) +>f : Symbol(f, Decl(divergentAccessorsTypes-56894-a.ts, 2, 16)) +>a : Symbol(a, Decl(divergentAccessorsTypes-56894-a.ts, 2, 20)) +>f : Symbol(f, Decl(divergentAccessorsTypes-56894-a.ts, 2, 37)) +>a : Symbol(a, Decl(divergentAccessorsTypes-56894-a.ts, 2, 41)) + + const r = x.f(id()) +>r : Symbol(r, Decl(divergentAccessorsTypes-56894-a.ts, 3, 9)) +>x.f : Symbol(f, Decl(divergentAccessorsTypes-56894-a.ts, 2, 16), Decl(divergentAccessorsTypes-56894-a.ts, 2, 37)) +>x : Symbol(x, Decl(divergentAccessorsTypes-56894-a.ts, 2, 12)) +>f : Symbol(f, Decl(divergentAccessorsTypes-56894-a.ts, 2, 16), Decl(divergentAccessorsTypes-56894-a.ts, 2, 37)) +>id : Symbol(id, Decl(divergentAccessorsTypes-56894-a.ts, 0, 13)) + +// ^ const id: <2>() => 2, +// ^ const r: 1 | 2 | 3 +} + +function f3(f: ((a:1|2)=>1|2) | ((a:2|3)=>2|3) ){ +>f3 : Symbol(f3, Decl(divergentAccessorsTypes-56894-a.ts, 6, 1)) +>f : Symbol(f, Decl(divergentAccessorsTypes-56894-a.ts, 8, 12)) +>a : Symbol(a, Decl(divergentAccessorsTypes-56894-a.ts, 8, 17)) +>a : Symbol(a, Decl(divergentAccessorsTypes-56894-a.ts, 8, 34)) + + const r = f(id()) +>r : Symbol(r, Decl(divergentAccessorsTypes-56894-a.ts, 9, 9)) +>f : Symbol(f, Decl(divergentAccessorsTypes-56894-a.ts, 8, 12)) +>id : Symbol(id, Decl(divergentAccessorsTypes-56894-a.ts, 0, 13)) + +// ^ const id: <2>() => 2, +// ^ const r: 1 | 2 | 3 +} + + +function f4(x: {set d(a:1|2); get r():1|2} | {set d(a:2|3); get r():2|3} ){ +>f4 : Symbol(f4, Decl(divergentAccessorsTypes-56894-a.ts, 12, 1)) +>x : Symbol(x, Decl(divergentAccessorsTypes-56894-a.ts, 15, 12)) +>d : Symbol(d, Decl(divergentAccessorsTypes-56894-a.ts, 15, 16)) +>a : Symbol(a, Decl(divergentAccessorsTypes-56894-a.ts, 15, 22)) +>r : Symbol(r, Decl(divergentAccessorsTypes-56894-a.ts, 15, 29)) +>d : Symbol(d, Decl(divergentAccessorsTypes-56894-a.ts, 15, 46)) +>a : Symbol(a, Decl(divergentAccessorsTypes-56894-a.ts, 15, 52)) +>r : Symbol(r, Decl(divergentAccessorsTypes-56894-a.ts, 15, 59)) + +// ^ (parameter) x: { d: 1 | 2; readonly r: 1 | 2; } | { d: 2 | 3; readonly r: 2 | 3; } + x.d = id(); +>x.d : Symbol(d, Decl(divergentAccessorsTypes-56894-a.ts, 15, 16), Decl(divergentAccessorsTypes-56894-a.ts, 15, 46)) +>x : Symbol(x, Decl(divergentAccessorsTypes-56894-a.ts, 15, 12)) +>d : Symbol(d, Decl(divergentAccessorsTypes-56894-a.ts, 15, 16), Decl(divergentAccessorsTypes-56894-a.ts, 15, 46)) +>id : Symbol(id, Decl(divergentAccessorsTypes-56894-a.ts, 0, 13)) + +// ^ const id: <1 | 2 | 3>() => 1 | 2 | 3 (5.3.2) +// ^ const id: <2>() => 2 (expecting, if a setter was treated as a function) + x.r; +>x.r : Symbol(r, Decl(divergentAccessorsTypes-56894-a.ts, 15, 29), Decl(divergentAccessorsTypes-56894-a.ts, 15, 59)) +>x : Symbol(x, Decl(divergentAccessorsTypes-56894-a.ts, 15, 12)) +>r : Symbol(r, Decl(divergentAccessorsTypes-56894-a.ts, 15, 29), Decl(divergentAccessorsTypes-56894-a.ts, 15, 59)) + +// ^ (property) r: 1 | 2 | 3 +} diff --git a/tests/baselines/reference/divergentAccessorsTypes-56894-a.types b/tests/baselines/reference/divergentAccessorsTypes-56894-a.types new file mode 100644 index 0000000000000..52cd561a880d4 --- /dev/null +++ b/tests/baselines/reference/divergentAccessorsTypes-56894-a.types @@ -0,0 +1,73 @@ +//// [tests/cases/compiler/-da/divergentAccessorsTypes-56894-a.ts] //// + +=== divergentAccessorsTypes-56894-a.ts === +declare const id:()=>T +>id : () => T + +function f2(x: {f:((a:1|2)=>1|2)} | {f:((a:2|3)=>2|3)} ){ +>f2 : (x: { f: (a: 1 | 2) => 1 | 2; } | { f: (a: 2 | 3) => 2 | 3; }) => void +>x : { f: (a: 1 | 2) => 1 | 2; } | { f: (a: 2 | 3) => 2 | 3; } +>f : (a: 1 | 2) => 1 | 2 +>a : 1 | 2 +>f : (a: 2 | 3) => 2 | 3 +>a : 2 | 3 + + const r = x.f(id()) +>r : 1 | 2 | 3 +>x.f(id()) : 1 | 2 | 3 +>x.f : ((a: 1 | 2) => 1 | 2) | ((a: 2 | 3) => 2 | 3) +>x : { f: (a: 1 | 2) => 1 | 2; } | { f: (a: 2 | 3) => 2 | 3; } +>f : ((a: 1 | 2) => 1 | 2) | ((a: 2 | 3) => 2 | 3) +>id() : 2 +>id : () => T + +// ^ const id: <2>() => 2, +// ^ const r: 1 | 2 | 3 +} + +function f3(f: ((a:1|2)=>1|2) | ((a:2|3)=>2|3) ){ +>f3 : (f: ((a: 1 | 2) => 1 | 2) | ((a: 2 | 3) => 2 | 3)) => void +>f : ((a: 1 | 2) => 1 | 2) | ((a: 2 | 3) => 2 | 3) +>a : 1 | 2 +>a : 2 | 3 + + const r = f(id()) +>r : 1 | 2 | 3 +>f(id()) : 1 | 2 | 3 +>f : ((a: 1 | 2) => 1 | 2) | ((a: 2 | 3) => 2 | 3) +>id() : 2 +>id : () => T + +// ^ const id: <2>() => 2, +// ^ const r: 1 | 2 | 3 +} + + +function f4(x: {set d(a:1|2); get r():1|2} | {set d(a:2|3); get r():2|3} ){ +>f4 : (x: { d: 1 | 2; readonly r: 1 | 2; } | { d: 2 | 3; readonly r: 2 | 3; }) => void +>x : { d: 1 | 2; readonly r: 1 | 2; } | { d: 2 | 3; readonly r: 2 | 3; } +>d : 1 | 2 +>a : 1 | 2 +>r : 1 | 2 +>d : 2 | 3 +>a : 2 | 3 +>r : 2 | 3 + +// ^ (parameter) x: { d: 1 | 2; readonly r: 1 | 2; } | { d: 2 | 3; readonly r: 2 | 3; } + x.d = id(); +>x.d = id() : 1 | 2 | 3 +>x.d : 1 | 2 | 3 +>x : { d: 1 | 2; readonly r: 1 | 2; } | { d: 2 | 3; readonly r: 2 | 3; } +>d : 1 | 2 | 3 +>id() : 1 | 2 | 3 +>id : () => T + +// ^ const id: <1 | 2 | 3>() => 1 | 2 | 3 (5.3.2) +// ^ const id: <2>() => 2 (expecting, if a setter was treated as a function) + x.r; +>x.r : 1 | 2 | 3 +>x : { d: 1 | 2; readonly r: 1 | 2; } | { d: 2 | 3; readonly r: 2 | 3; } +>r : 1 | 2 | 3 + +// ^ (property) r: 1 | 2 | 3 +} diff --git a/tests/baselines/reference/divergentAccessorsTypes-56894-b.errors.txt b/tests/baselines/reference/divergentAccessorsTypes-56894-b.errors.txt new file mode 100644 index 0000000000000..227afadff1168 --- /dev/null +++ b/tests/baselines/reference/divergentAccessorsTypes-56894-b.errors.txt @@ -0,0 +1,64 @@ +divergentAccessorsTypes-56894-b.ts(26,9): error TS2367: This comparison appears to be unintentional because the types '3' and '1' have no overlap. +divergentAccessorsTypes-56894-b.ts(34,5): error TS2322: Type '1' is not assignable to type '2'. +divergentAccessorsTypes-56894-b.ts(35,5): error TS2322: Type '1' is not assignable to type '2'. +divergentAccessorsTypes-56894-b.ts(36,5): error TS2322: Type '1' is not assignable to type '2'. +divergentAccessorsTypes-56894-b.ts(37,9): error TS2367: This comparison appears to be unintentional because the types '2' and '1' have no overlap. +divergentAccessorsTypes-56894-b.ts(40,9): error TS2367: This comparison appears to be unintentional because the types '2' and '1' have no overlap. + + +==== divergentAccessorsTypes-56894-b.ts (6 errors) ==== + type T12 = { + a: 1|2; + set gsa(x: 1|2); + get gsa(): 1|2; + set sb(x: 1|2); + get gc(): 1|2; + }; + type T23 = { + a: 2|3; + set gsa(x: 2|3); + get gsa(): 2|3; + set sb(x: 2|3); + get gc(): 2|3; + }; + + function fu(u:T12|T23) { + u.a = 1; + u.sb = 1; + u.gsa = 1; + u.a = 2; + u.sb = 2; + u.gsa = 2; + u.a = 3; + u.sb = 3; + u.gsa = 3; + if (u.gsa === 1) { + ~~~~~~~~~~~ +!!! error TS2367: This comparison appears to be unintentional because the types '3' and '1' have no overlap. + u.gsa; + } + if (u.gc === 1) { + u.gc; + } + } + function fi(i:T12&T23) { + i.a = 1; // error before & after + ~~~ +!!! error TS2322: Type '1' is not assignable to type '2'. + i.sb = 1; // error before & after + ~~~~ +!!! error TS2322: Type '1' is not assignable to type '2'. + i.gsa = 1; // error before & after + ~~~~~ +!!! error TS2322: Type '1' is not assignable to type '2'. + if (i.gsa === 1) { // error before & after + ~~~~~~~~~~~ +!!! error TS2367: This comparison appears to be unintentional because the types '2' and '1' have no overlap. + i.gsa; + } + if (i.gc === 1) { // error before & after + ~~~~~~~~~~ +!!! error TS2367: This comparison appears to be unintentional because the types '2' and '1' have no overlap. + i.gc; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/divergentAccessorsTypes-56894-b.js b/tests/baselines/reference/divergentAccessorsTypes-56894-b.js new file mode 100644 index 0000000000000..97eff5fa2f3db --- /dev/null +++ b/tests/baselines/reference/divergentAccessorsTypes-56894-b.js @@ -0,0 +1,76 @@ +//// [tests/cases/compiler/-da/divergentAccessorsTypes-56894-b.ts] //// + +//// [divergentAccessorsTypes-56894-b.ts] +type T12 = { + a: 1|2; + set gsa(x: 1|2); + get gsa(): 1|2; + set sb(x: 1|2); + get gc(): 1|2; +}; +type T23 = { + a: 2|3; + set gsa(x: 2|3); + get gsa(): 2|3; + set sb(x: 2|3); + get gc(): 2|3; +}; + +function fu(u:T12|T23) { + u.a = 1; + u.sb = 1; + u.gsa = 1; + u.a = 2; + u.sb = 2; + u.gsa = 2; + u.a = 3; + u.sb = 3; + u.gsa = 3; + if (u.gsa === 1) { + u.gsa; + } + if (u.gc === 1) { + u.gc; + } +} +function fi(i:T12&T23) { + i.a = 1; // error before & after + i.sb = 1; // error before & after + i.gsa = 1; // error before & after + if (i.gsa === 1) { // error before & after + i.gsa; + } + if (i.gc === 1) { // error before & after + i.gc; + } +} + +//// [divergentAccessorsTypes-56894-b.js] +function fu(u) { + u.a = 1; + u.sb = 1; + u.gsa = 1; + u.a = 2; + u.sb = 2; + u.gsa = 2; + u.a = 3; + u.sb = 3; + u.gsa = 3; + if (u.gsa === 1) { + u.gsa; + } + if (u.gc === 1) { + u.gc; + } +} +function fi(i) { + i.a = 1; // error before & after + i.sb = 1; // error before & after + i.gsa = 1; // error before & after + if (i.gsa === 1) { // error before & after + i.gsa; + } + if (i.gc === 1) { // error before & after + i.gc; + } +} diff --git a/tests/baselines/reference/divergentAccessorsTypes-56894-b.symbols b/tests/baselines/reference/divergentAccessorsTypes-56894-b.symbols new file mode 100644 index 0000000000000..cce11717aafd2 --- /dev/null +++ b/tests/baselines/reference/divergentAccessorsTypes-56894-b.symbols @@ -0,0 +1,160 @@ +//// [tests/cases/compiler/-da/divergentAccessorsTypes-56894-b.ts] //// + +=== divergentAccessorsTypes-56894-b.ts === +type T12 = { +>T12 : Symbol(T12, Decl(divergentAccessorsTypes-56894-b.ts, 0, 0)) + + a: 1|2; +>a : Symbol(a, Decl(divergentAccessorsTypes-56894-b.ts, 0, 12)) + + set gsa(x: 1|2); +>gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20)) +>x : Symbol(x, Decl(divergentAccessorsTypes-56894-b.ts, 2, 12)) + + get gsa(): 1|2; +>gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20)) + + set sb(x: 1|2); +>sb : Symbol(sb, Decl(divergentAccessorsTypes-56894-b.ts, 3, 19)) +>x : Symbol(x, Decl(divergentAccessorsTypes-56894-b.ts, 4, 11)) + + get gc(): 1|2; +>gc : Symbol(gc, Decl(divergentAccessorsTypes-56894-b.ts, 4, 19)) + +}; +type T23 = { +>T23 : Symbol(T23, Decl(divergentAccessorsTypes-56894-b.ts, 6, 2)) + + a: 2|3; +>a : Symbol(a, Decl(divergentAccessorsTypes-56894-b.ts, 7, 12)) + + set gsa(x: 2|3); +>gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) +>x : Symbol(x, Decl(divergentAccessorsTypes-56894-b.ts, 9, 12)) + + get gsa(): 2|3; +>gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) + + set sb(x: 2|3); +>sb : Symbol(sb, Decl(divergentAccessorsTypes-56894-b.ts, 10, 19)) +>x : Symbol(x, Decl(divergentAccessorsTypes-56894-b.ts, 11, 11)) + + get gc(): 2|3; +>gc : Symbol(gc, Decl(divergentAccessorsTypes-56894-b.ts, 11, 19)) + +}; + +function fu(u:T12|T23) { +>fu : Symbol(fu, Decl(divergentAccessorsTypes-56894-b.ts, 13, 2)) +>u : Symbol(u, Decl(divergentAccessorsTypes-56894-b.ts, 15, 12)) +>T12 : Symbol(T12, Decl(divergentAccessorsTypes-56894-b.ts, 0, 0)) +>T23 : Symbol(T23, Decl(divergentAccessorsTypes-56894-b.ts, 6, 2)) + + u.a = 1; +>u.a : Symbol(a, Decl(divergentAccessorsTypes-56894-b.ts, 0, 12), Decl(divergentAccessorsTypes-56894-b.ts, 7, 12)) +>u : Symbol(u, Decl(divergentAccessorsTypes-56894-b.ts, 15, 12)) +>a : Symbol(a, Decl(divergentAccessorsTypes-56894-b.ts, 0, 12), Decl(divergentAccessorsTypes-56894-b.ts, 7, 12)) + + u.sb = 1; +>u.sb : Symbol(sb, Decl(divergentAccessorsTypes-56894-b.ts, 3, 19), Decl(divergentAccessorsTypes-56894-b.ts, 10, 19)) +>u : Symbol(u, Decl(divergentAccessorsTypes-56894-b.ts, 15, 12)) +>sb : Symbol(sb, Decl(divergentAccessorsTypes-56894-b.ts, 3, 19), Decl(divergentAccessorsTypes-56894-b.ts, 10, 19)) + + u.gsa = 1; +>u.gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20), Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) +>u : Symbol(u, Decl(divergentAccessorsTypes-56894-b.ts, 15, 12)) +>gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20), Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) + + u.a = 2; +>u.a : Symbol(a, Decl(divergentAccessorsTypes-56894-b.ts, 0, 12), Decl(divergentAccessorsTypes-56894-b.ts, 7, 12)) +>u : Symbol(u, Decl(divergentAccessorsTypes-56894-b.ts, 15, 12)) +>a : Symbol(a, Decl(divergentAccessorsTypes-56894-b.ts, 0, 12), Decl(divergentAccessorsTypes-56894-b.ts, 7, 12)) + + u.sb = 2; +>u.sb : Symbol(sb, Decl(divergentAccessorsTypes-56894-b.ts, 3, 19), Decl(divergentAccessorsTypes-56894-b.ts, 10, 19)) +>u : Symbol(u, Decl(divergentAccessorsTypes-56894-b.ts, 15, 12)) +>sb : Symbol(sb, Decl(divergentAccessorsTypes-56894-b.ts, 3, 19), Decl(divergentAccessorsTypes-56894-b.ts, 10, 19)) + + u.gsa = 2; +>u.gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20), Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) +>u : Symbol(u, Decl(divergentAccessorsTypes-56894-b.ts, 15, 12)) +>gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20), Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) + + u.a = 3; +>u.a : Symbol(a, Decl(divergentAccessorsTypes-56894-b.ts, 0, 12), Decl(divergentAccessorsTypes-56894-b.ts, 7, 12)) +>u : Symbol(u, Decl(divergentAccessorsTypes-56894-b.ts, 15, 12)) +>a : Symbol(a, Decl(divergentAccessorsTypes-56894-b.ts, 0, 12), Decl(divergentAccessorsTypes-56894-b.ts, 7, 12)) + + u.sb = 3; +>u.sb : Symbol(sb, Decl(divergentAccessorsTypes-56894-b.ts, 3, 19), Decl(divergentAccessorsTypes-56894-b.ts, 10, 19)) +>u : Symbol(u, Decl(divergentAccessorsTypes-56894-b.ts, 15, 12)) +>sb : Symbol(sb, Decl(divergentAccessorsTypes-56894-b.ts, 3, 19), Decl(divergentAccessorsTypes-56894-b.ts, 10, 19)) + + u.gsa = 3; +>u.gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20), Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) +>u : Symbol(u, Decl(divergentAccessorsTypes-56894-b.ts, 15, 12)) +>gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20), Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) + + if (u.gsa === 1) { +>u.gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20), Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) +>u : Symbol(u, Decl(divergentAccessorsTypes-56894-b.ts, 15, 12)) +>gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20), Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) + + u.gsa; +>u.gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20)) +>u : Symbol(u, Decl(divergentAccessorsTypes-56894-b.ts, 15, 12)) +>gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20)) + } + if (u.gc === 1) { +>u.gc : Symbol(gc, Decl(divergentAccessorsTypes-56894-b.ts, 4, 19), Decl(divergentAccessorsTypes-56894-b.ts, 11, 19)) +>u : Symbol(u, Decl(divergentAccessorsTypes-56894-b.ts, 15, 12)) +>gc : Symbol(gc, Decl(divergentAccessorsTypes-56894-b.ts, 4, 19), Decl(divergentAccessorsTypes-56894-b.ts, 11, 19)) + + u.gc; +>u.gc : Symbol(gc, Decl(divergentAccessorsTypes-56894-b.ts, 4, 19)) +>u : Symbol(u, Decl(divergentAccessorsTypes-56894-b.ts, 15, 12)) +>gc : Symbol(gc, Decl(divergentAccessorsTypes-56894-b.ts, 4, 19)) + } +} +function fi(i:T12&T23) { +>fi : Symbol(fi, Decl(divergentAccessorsTypes-56894-b.ts, 31, 1)) +>i : Symbol(i, Decl(divergentAccessorsTypes-56894-b.ts, 32, 12)) +>T12 : Symbol(T12, Decl(divergentAccessorsTypes-56894-b.ts, 0, 0)) +>T23 : Symbol(T23, Decl(divergentAccessorsTypes-56894-b.ts, 6, 2)) + + i.a = 1; // error before & after +>i.a : Symbol(a, Decl(divergentAccessorsTypes-56894-b.ts, 0, 12), Decl(divergentAccessorsTypes-56894-b.ts, 7, 12)) +>i : Symbol(i, Decl(divergentAccessorsTypes-56894-b.ts, 32, 12)) +>a : Symbol(a, Decl(divergentAccessorsTypes-56894-b.ts, 0, 12), Decl(divergentAccessorsTypes-56894-b.ts, 7, 12)) + + i.sb = 1; // error before & after +>i.sb : Symbol(sb, Decl(divergentAccessorsTypes-56894-b.ts, 3, 19), Decl(divergentAccessorsTypes-56894-b.ts, 10, 19)) +>i : Symbol(i, Decl(divergentAccessorsTypes-56894-b.ts, 32, 12)) +>sb : Symbol(sb, Decl(divergentAccessorsTypes-56894-b.ts, 3, 19), Decl(divergentAccessorsTypes-56894-b.ts, 10, 19)) + + i.gsa = 1; // error before & after +>i.gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20), Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) +>i : Symbol(i, Decl(divergentAccessorsTypes-56894-b.ts, 32, 12)) +>gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20), Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) + + if (i.gsa === 1) { // error before & after +>i.gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20), Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) +>i : Symbol(i, Decl(divergentAccessorsTypes-56894-b.ts, 32, 12)) +>gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20), Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) + + i.gsa; +>i.gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20), Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) +>i : Symbol(i, Decl(divergentAccessorsTypes-56894-b.ts, 32, 12)) +>gsa : Symbol(gsa, Decl(divergentAccessorsTypes-56894-b.ts, 1, 11), Decl(divergentAccessorsTypes-56894-b.ts, 2, 20), Decl(divergentAccessorsTypes-56894-b.ts, 8, 11), Decl(divergentAccessorsTypes-56894-b.ts, 9, 20)) + } + if (i.gc === 1) { // error before & after +>i.gc : Symbol(gc, Decl(divergentAccessorsTypes-56894-b.ts, 4, 19), Decl(divergentAccessorsTypes-56894-b.ts, 11, 19)) +>i : Symbol(i, Decl(divergentAccessorsTypes-56894-b.ts, 32, 12)) +>gc : Symbol(gc, Decl(divergentAccessorsTypes-56894-b.ts, 4, 19), Decl(divergentAccessorsTypes-56894-b.ts, 11, 19)) + + i.gc; +>i.gc : Symbol(gc, Decl(divergentAccessorsTypes-56894-b.ts, 4, 19), Decl(divergentAccessorsTypes-56894-b.ts, 11, 19)) +>i : Symbol(i, Decl(divergentAccessorsTypes-56894-b.ts, 32, 12)) +>gc : Symbol(gc, Decl(divergentAccessorsTypes-56894-b.ts, 4, 19), Decl(divergentAccessorsTypes-56894-b.ts, 11, 19)) + } +} diff --git a/tests/baselines/reference/divergentAccessorsTypes-56894-b.types b/tests/baselines/reference/divergentAccessorsTypes-56894-b.types new file mode 100644 index 0000000000000..dc0243cffa6f7 --- /dev/null +++ b/tests/baselines/reference/divergentAccessorsTypes-56894-b.types @@ -0,0 +1,188 @@ +//// [tests/cases/compiler/-da/divergentAccessorsTypes-56894-b.ts] //// + +=== divergentAccessorsTypes-56894-b.ts === +type T12 = { +>T12 : { a: 1 | 2; gsa: 1 | 2; sb: 1 | 2; readonly gc: 1 | 2; } + + a: 1|2; +>a : 1 | 2 + + set gsa(x: 1|2); +>gsa : 1 | 2 +>x : 1 | 2 + + get gsa(): 1|2; +>gsa : 1 | 2 + + set sb(x: 1|2); +>sb : 1 | 2 +>x : 1 | 2 + + get gc(): 1|2; +>gc : 1 | 2 + +}; +type T23 = { +>T23 : { a: 2 | 3; gsa: 2 | 3; sb: 2 | 3; readonly gc: 2 | 3; } + + a: 2|3; +>a : 2 | 3 + + set gsa(x: 2|3); +>gsa : 2 | 3 +>x : 2 | 3 + + get gsa(): 2|3; +>gsa : 2 | 3 + + set sb(x: 2|3); +>sb : 2 | 3 +>x : 2 | 3 + + get gc(): 2|3; +>gc : 2 | 3 + +}; + +function fu(u:T12|T23) { +>fu : (u: T12 | T23) => void +>u : T12 | T23 + + u.a = 1; +>u.a = 1 : 1 +>u.a : 1 | 2 | 3 +>u : T12 | T23 +>a : 1 | 2 | 3 +>1 : 1 + + u.sb = 1; +>u.sb = 1 : 1 +>u.sb : 1 | 2 | 3 +>u : T12 | T23 +>sb : 1 | 2 | 3 +>1 : 1 + + u.gsa = 1; +>u.gsa = 1 : 1 +>u.gsa : 1 | 2 | 3 +>u : T12 | T23 +>gsa : 1 | 2 | 3 +>1 : 1 + + u.a = 2; +>u.a = 2 : 2 +>u.a : 1 | 2 | 3 +>u : T12 | T23 +>a : 1 | 2 | 3 +>2 : 2 + + u.sb = 2; +>u.sb = 2 : 2 +>u.sb : 1 | 2 | 3 +>u : T12 | T23 +>sb : 1 | 2 | 3 +>2 : 2 + + u.gsa = 2; +>u.gsa = 2 : 2 +>u.gsa : 1 | 2 | 3 +>u : T12 | T23 +>gsa : 1 | 2 | 3 +>2 : 2 + + u.a = 3; +>u.a = 3 : 3 +>u.a : 1 | 2 | 3 +>u : T12 | T23 +>a : 1 | 2 | 3 +>3 : 3 + + u.sb = 3; +>u.sb = 3 : 3 +>u.sb : 1 | 2 | 3 +>u : T12 | T23 +>sb : 1 | 2 | 3 +>3 : 3 + + u.gsa = 3; +>u.gsa = 3 : 3 +>u.gsa : 1 | 2 | 3 +>u : T12 | T23 +>gsa : 1 | 2 | 3 +>3 : 3 + + if (u.gsa === 1) { +>u.gsa === 1 : boolean +>u.gsa : 3 +>u : T12 | T23 +>gsa : 3 +>1 : 1 + + u.gsa; +>u.gsa : 1 +>u : T12 +>gsa : 1 + } + if (u.gc === 1) { +>u.gc === 1 : boolean +>u.gc : 1 | 2 | 3 +>u : T12 | T23 +>gc : 1 | 2 | 3 +>1 : 1 + + u.gc; +>u.gc : 1 +>u : T12 +>gc : 1 + } +} +function fi(i:T12&T23) { +>fi : (i: T12 & T23) => void +>i : T12 & T23 + + i.a = 1; // error before & after +>i.a = 1 : 1 +>i.a : 2 +>i : T12 & T23 +>a : 2 +>1 : 1 + + i.sb = 1; // error before & after +>i.sb = 1 : 1 +>i.sb : 2 +>i : T12 & T23 +>sb : 2 +>1 : 1 + + i.gsa = 1; // error before & after +>i.gsa = 1 : 1 +>i.gsa : 2 +>i : T12 & T23 +>gsa : 2 +>1 : 1 + + if (i.gsa === 1) { // error before & after +>i.gsa === 1 : boolean +>i.gsa : 2 +>i : T12 & T23 +>gsa : 2 +>1 : 1 + + i.gsa; +>i.gsa : never +>i : T12 & T23 +>gsa : never + } + if (i.gc === 1) { // error before & after +>i.gc === 1 : boolean +>i.gc : 2 +>i : T12 & T23 +>gc : 2 +>1 : 1 + + i.gc; +>i.gc : never +>i : T12 & T23 +>gc : never + } +} diff --git a/tests/baselines/reference/divergentAccessorsTypes3.errors.txt b/tests/baselines/reference/divergentAccessorsTypes3.errors.txt new file mode 100644 index 0000000000000..f9aa2e1ff9f55 --- /dev/null +++ b/tests/baselines/reference/divergentAccessorsTypes3.errors.txt @@ -0,0 +1,64 @@ +divergentAccessorsTypes3.ts(33,1): error TS2322: Type 'number' is not assignable to type 'string'. +divergentAccessorsTypes3.ts(36,1): error TS2322: Type 'number' is not assignable to type 'never'. +divergentAccessorsTypes3.ts(37,1): error TS2322: Type 'string' is not assignable to type 'never'. +divergentAccessorsTypes3.ts(38,1): error TS2322: Type 'boolean' is not assignable to type 'never'. +divergentAccessorsTypes3.ts(40,1): error TS2322: Type 'number' is not assignable to type 'string'. +divergentAccessorsTypes3.ts(42,1): error TS2322: Type 'boolean' is not assignable to type 'string'. + + +==== divergentAccessorsTypes3.ts (6 errors) ==== + class One { + get prop1(): string { return ""; } + set prop1(s: string | number) { } + + get prop2(): string { return ""; } + set prop2(s: string | number) { } + + prop3: number; + + get prop4(): string { return ""; } + set prop4(s: string | number) { } + } + + class Two { + get prop1(): string { return ""; } + set prop1(s: string | number) { } + + get prop2(): string { return ""; } + set prop2(s: string) { } + + get prop3(): string { return ""; } + set prop3(s: string | boolean) { } + + get prop4(): string { return ""; } + set prop4(s: string | boolean) { } + } + + declare const u1: One|Two; + + u1.prop1 = 42; + u1.prop1 = "hello"; + + u1.prop2 = 42; + ~~~~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. + u1.prop2 = "hello"; + + u1.prop3 = 42; + ~~~~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'never'. + u1.prop3 = "hello"; + ~~~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type 'never'. + u1.prop3 = true; + ~~~~~~~~ +!!! error TS2322: Type 'boolean' is not assignable to type 'never'. + + u1.prop4 = 42; + ~~~~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. + u1.prop4 = "hello"; + u1.prop4 = true; + ~~~~~~~~ +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. + \ No newline at end of file diff --git a/tests/baselines/reference/divergentAccessorsTypes3.types b/tests/baselines/reference/divergentAccessorsTypes3.types index d532953bd6680..8bb9abb6c43ac 100644 --- a/tests/baselines/reference/divergentAccessorsTypes3.types +++ b/tests/baselines/reference/divergentAccessorsTypes3.types @@ -87,57 +87,57 @@ u1.prop1 = "hello"; u1.prop2 = 42; >u1.prop2 = 42 : 42 ->u1.prop2 : string | number +>u1.prop2 : string >u1 : One | Two ->prop2 : string | number +>prop2 : string >42 : 42 u1.prop2 = "hello"; >u1.prop2 = "hello" : "hello" ->u1.prop2 : string | number +>u1.prop2 : string >u1 : One | Two ->prop2 : string | number +>prop2 : string >"hello" : "hello" u1.prop3 = 42; >u1.prop3 = 42 : 42 ->u1.prop3 : string | number | boolean +>u1.prop3 : never >u1 : One | Two ->prop3 : string | number | boolean +>prop3 : never >42 : 42 u1.prop3 = "hello"; >u1.prop3 = "hello" : "hello" ->u1.prop3 : string | number | boolean +>u1.prop3 : never >u1 : One | Two ->prop3 : string | number | boolean +>prop3 : never >"hello" : "hello" u1.prop3 = true; >u1.prop3 = true : true ->u1.prop3 : string | number | boolean +>u1.prop3 : never >u1 : One | Two ->prop3 : string | number | boolean +>prop3 : never >true : true u1.prop4 = 42; >u1.prop4 = 42 : 42 ->u1.prop4 : string | number | boolean +>u1.prop4 : string >u1 : One | Two ->prop4 : string | number | boolean +>prop4 : string >42 : 42 u1.prop4 = "hello"; >u1.prop4 = "hello" : "hello" ->u1.prop4 : string | number | boolean +>u1.prop4 : string >u1 : One | Two ->prop4 : string | number | boolean +>prop4 : string >"hello" : "hello" u1.prop4 = true; >u1.prop4 = true : true ->u1.prop4 : string | number | boolean +>u1.prop4 : string >u1 : One | Two ->prop4 : string | number | boolean +>prop4 : string >true : true diff --git a/tests/baselines/reference/divergentAccessorsTypes4.errors.txt b/tests/baselines/reference/divergentAccessorsTypes4.errors.txt deleted file mode 100644 index bd3bed24204ac..0000000000000 --- a/tests/baselines/reference/divergentAccessorsTypes4.errors.txt +++ /dev/null @@ -1,36 +0,0 @@ -divergentAccessorsTypes4.ts(29,1): error TS2322: Type '"hello"' is not assignable to type '42'. - - -==== divergentAccessorsTypes4.ts (1 errors) ==== - class One { - get prop1(): string { return ""; } - set prop1(s: string | number) { } - - prop2: number; - } - - class Two { - get prop1(): "hello" { return "hello"; } - set prop1(s: "hello" | number) { } - - get prop2(): string { return ""; } - set prop2(s: string | 42) { } - - } - - declare const i: One & Two; - - // "hello" - i.prop1; - // number | "hello" - i.prop1 = 42; - i.prop1 = "hello"; - - // never - i.prop2; - // 42 - i.prop2 = 42; - i.prop2 = "hello"; // error - ~~~~~~~ -!!! error TS2322: Type '"hello"' is not assignable to type '42'. - \ No newline at end of file diff --git a/tests/baselines/reference/divergentAccessorsTypes4.js b/tests/baselines/reference/divergentAccessorsTypes4.js index aed09844941d3..a3c9851cd267e 100644 --- a/tests/baselines/reference/divergentAccessorsTypes4.js +++ b/tests/baselines/reference/divergentAccessorsTypes4.js @@ -21,15 +21,15 @@ declare const i: One & Two; // "hello" i.prop1; -// number | "hello" +// string | number i.prop1 = 42; i.prop1 = "hello"; // never i.prop2; -// 42 +// string | number i.prop2 = 42; -i.prop2 = "hello"; // error +i.prop2 = "hello"; //// [divergentAccessorsTypes4.js] @@ -63,11 +63,11 @@ var Two = /** @class */ (function () { }()); // "hello" i.prop1; -// number | "hello" +// string | number i.prop1 = 42; i.prop1 = "hello"; // never i.prop2; -// 42 +// string | number i.prop2 = 42; -i.prop2 = "hello"; // error +i.prop2 = "hello"; diff --git a/tests/baselines/reference/divergentAccessorsTypes4.symbols b/tests/baselines/reference/divergentAccessorsTypes4.symbols index cb645cea8a6e5..862ab90bcf580 100644 --- a/tests/baselines/reference/divergentAccessorsTypes4.symbols +++ b/tests/baselines/reference/divergentAccessorsTypes4.symbols @@ -45,7 +45,7 @@ i.prop1; >i : Symbol(i, Decl(divergentAccessorsTypes4.ts, 16, 13)) >prop1 : Symbol(prop1, Decl(divergentAccessorsTypes4.ts, 0, 11), Decl(divergentAccessorsTypes4.ts, 1, 36), Decl(divergentAccessorsTypes4.ts, 7, 11), Decl(divergentAccessorsTypes4.ts, 8, 42)) -// number | "hello" +// string | number i.prop1 = 42; >i.prop1 : Symbol(prop1, Decl(divergentAccessorsTypes4.ts, 0, 11), Decl(divergentAccessorsTypes4.ts, 1, 36), Decl(divergentAccessorsTypes4.ts, 7, 11), Decl(divergentAccessorsTypes4.ts, 8, 42)) >i : Symbol(i, Decl(divergentAccessorsTypes4.ts, 16, 13)) @@ -62,13 +62,13 @@ i.prop2; >i : Symbol(i, Decl(divergentAccessorsTypes4.ts, 16, 13)) >prop2 : Symbol(prop2, Decl(divergentAccessorsTypes4.ts, 2, 35), Decl(divergentAccessorsTypes4.ts, 9, 36), Decl(divergentAccessorsTypes4.ts, 11, 36)) -// 42 +// string | number i.prop2 = 42; >i.prop2 : Symbol(prop2, Decl(divergentAccessorsTypes4.ts, 2, 35), Decl(divergentAccessorsTypes4.ts, 9, 36), Decl(divergentAccessorsTypes4.ts, 11, 36)) >i : Symbol(i, Decl(divergentAccessorsTypes4.ts, 16, 13)) >prop2 : Symbol(prop2, Decl(divergentAccessorsTypes4.ts, 2, 35), Decl(divergentAccessorsTypes4.ts, 9, 36), Decl(divergentAccessorsTypes4.ts, 11, 36)) -i.prop2 = "hello"; // error +i.prop2 = "hello"; >i.prop2 : Symbol(prop2, Decl(divergentAccessorsTypes4.ts, 2, 35), Decl(divergentAccessorsTypes4.ts, 9, 36), Decl(divergentAccessorsTypes4.ts, 11, 36)) >i : Symbol(i, Decl(divergentAccessorsTypes4.ts, 16, 13)) >prop2 : Symbol(prop2, Decl(divergentAccessorsTypes4.ts, 2, 35), Decl(divergentAccessorsTypes4.ts, 9, 36), Decl(divergentAccessorsTypes4.ts, 11, 36)) diff --git a/tests/baselines/reference/divergentAccessorsTypes4.types b/tests/baselines/reference/divergentAccessorsTypes4.types index 736f910a093ca..3f4ffa5ed58b8 100644 --- a/tests/baselines/reference/divergentAccessorsTypes4.types +++ b/tests/baselines/reference/divergentAccessorsTypes4.types @@ -46,19 +46,19 @@ i.prop1; >i : One & Two >prop1 : "hello" -// number | "hello" +// string | number i.prop1 = 42; >i.prop1 = 42 : 42 ->i.prop1 : number | "hello" +>i.prop1 : string | number >i : One & Two ->prop1 : number | "hello" +>prop1 : string | number >42 : 42 i.prop1 = "hello"; >i.prop1 = "hello" : "hello" ->i.prop1 : number | "hello" +>i.prop1 : string | number >i : One & Two ->prop1 : number | "hello" +>prop1 : string | number >"hello" : "hello" // never @@ -67,18 +67,18 @@ i.prop2; >i : One & Two >prop2 : never -// 42 +// string | number i.prop2 = 42; >i.prop2 = 42 : 42 ->i.prop2 : 42 +>i.prop2 : string | number >i : One & Two ->prop2 : 42 +>prop2 : string | number >42 : 42 -i.prop2 = "hello"; // error +i.prop2 = "hello"; >i.prop2 = "hello" : "hello" ->i.prop2 : 42 +>i.prop2 : string | number >i : One & Two ->prop2 : 42 +>prop2 : string | number >"hello" : "hello" diff --git a/tests/baselines/reference/divergentAccessorsTypes5.errors.txt b/tests/baselines/reference/divergentAccessorsTypes5.errors.txt deleted file mode 100644 index 00b77b09e9cd4..0000000000000 --- a/tests/baselines/reference/divergentAccessorsTypes5.errors.txt +++ /dev/null @@ -1,46 +0,0 @@ -divergentAccessorsTypes5.ts(31,1): error TS2322: Type '42' is not assignable to type '"hello"'. -divergentAccessorsTypes5.ts(36,1): error TS2322: Type '"hello"' is not assignable to type '42'. - - -==== divergentAccessorsTypes5.ts (2 errors) ==== - // Not really different from divergentAccessorsTypes4.ts, - // but goes through the deferred type code - - class One { - get prop1(): string { return ""; } - set prop1(s: string | number) { } - - prop2: number; - } - - class Two { - get prop1(): "hello" { return "hello"; } - set prop1(s: "hello" | number) { } - - get prop2(): string { return ""; } - set prop2(s: string | 42) { } - - } - - class Three { - get prop1(): "hello" { return "hello"; } - set prop1(s: "hello" | boolean) { } - - get prop2(): string { return ""; } - set prop2(s: string | number | boolean) { } - } - - declare const i: One & Two & Three; - - // "hello" - i.prop1 = 42; // error - ~~~~~~~ -!!! error TS2322: Type '42' is not assignable to type '"hello"'. - i.prop1 = "hello"; - - // 42 - i.prop2 = 42; - i.prop2 = "hello"; // error - ~~~~~~~ -!!! error TS2322: Type '"hello"' is not assignable to type '42'. - \ No newline at end of file diff --git a/tests/baselines/reference/divergentAccessorsTypes5.js b/tests/baselines/reference/divergentAccessorsTypes5.js index 780f38db7ed00..3716d18359283 100644 --- a/tests/baselines/reference/divergentAccessorsTypes5.js +++ b/tests/baselines/reference/divergentAccessorsTypes5.js @@ -31,12 +31,12 @@ class Three { declare const i: One & Two & Three; // "hello" -i.prop1 = 42; // error +i.prop1 = 42; i.prop1 = "hello"; // 42 i.prop2 = 42; -i.prop2 = "hello"; // error +i.prop2 = "hello"; //// [divergentAccessorsTypes5.js] @@ -88,8 +88,8 @@ var Three = /** @class */ (function () { return Three; }()); // "hello" -i.prop1 = 42; // error +i.prop1 = 42; i.prop1 = "hello"; // 42 i.prop2 = 42; -i.prop2 = "hello"; // error +i.prop2 = "hello"; diff --git a/tests/baselines/reference/divergentAccessorsTypes5.symbols b/tests/baselines/reference/divergentAccessorsTypes5.symbols index b1df2dfb25939..39264195e6029 100644 --- a/tests/baselines/reference/divergentAccessorsTypes5.symbols +++ b/tests/baselines/reference/divergentAccessorsTypes5.symbols @@ -62,7 +62,7 @@ declare const i: One & Two & Three; >Three : Symbol(Three, Decl(divergentAccessorsTypes5.ts, 17, 1)) // "hello" -i.prop1 = 42; // error +i.prop1 = 42; >i.prop1 : Symbol(prop1, Decl(divergentAccessorsTypes5.ts, 3, 11), Decl(divergentAccessorsTypes5.ts, 4, 36), Decl(divergentAccessorsTypes5.ts, 10, 11), Decl(divergentAccessorsTypes5.ts, 11, 42), Decl(divergentAccessorsTypes5.ts, 19, 13) ... and 1 more) >i : Symbol(i, Decl(divergentAccessorsTypes5.ts, 27, 13)) >prop1 : Symbol(prop1, Decl(divergentAccessorsTypes5.ts, 3, 11), Decl(divergentAccessorsTypes5.ts, 4, 36), Decl(divergentAccessorsTypes5.ts, 10, 11), Decl(divergentAccessorsTypes5.ts, 11, 42), Decl(divergentAccessorsTypes5.ts, 19, 13) ... and 1 more) @@ -78,7 +78,7 @@ i.prop2 = 42; >i : Symbol(i, Decl(divergentAccessorsTypes5.ts, 27, 13)) >prop2 : Symbol(prop2, Decl(divergentAccessorsTypes5.ts, 5, 35), Decl(divergentAccessorsTypes5.ts, 12, 36), Decl(divergentAccessorsTypes5.ts, 14, 36), Decl(divergentAccessorsTypes5.ts, 21, 37), Decl(divergentAccessorsTypes5.ts, 23, 36)) -i.prop2 = "hello"; // error +i.prop2 = "hello"; >i.prop2 : Symbol(prop2, Decl(divergentAccessorsTypes5.ts, 5, 35), Decl(divergentAccessorsTypes5.ts, 12, 36), Decl(divergentAccessorsTypes5.ts, 14, 36), Decl(divergentAccessorsTypes5.ts, 21, 37), Decl(divergentAccessorsTypes5.ts, 23, 36)) >i : Symbol(i, Decl(divergentAccessorsTypes5.ts, 27, 13)) >prop2 : Symbol(prop2, Decl(divergentAccessorsTypes5.ts, 5, 35), Decl(divergentAccessorsTypes5.ts, 12, 36), Decl(divergentAccessorsTypes5.ts, 14, 36), Decl(divergentAccessorsTypes5.ts, 21, 37), Decl(divergentAccessorsTypes5.ts, 23, 36)) diff --git a/tests/baselines/reference/divergentAccessorsTypes5.types b/tests/baselines/reference/divergentAccessorsTypes5.types index f47b6f238024f..d3a7b73743a70 100644 --- a/tests/baselines/reference/divergentAccessorsTypes5.types +++ b/tests/baselines/reference/divergentAccessorsTypes5.types @@ -64,32 +64,32 @@ declare const i: One & Two & Three; >i : One & Two & Three // "hello" -i.prop1 = 42; // error +i.prop1 = 42; >i.prop1 = 42 : 42 ->i.prop1 : "hello" +>i.prop1 : string | number | boolean >i : One & Two & Three ->prop1 : "hello" +>prop1 : string | number | boolean >42 : 42 i.prop1 = "hello"; >i.prop1 = "hello" : "hello" ->i.prop1 : "hello" +>i.prop1 : string | number | boolean >i : One & Two & Three ->prop1 : "hello" +>prop1 : string | number | boolean >"hello" : "hello" // 42 i.prop2 = 42; >i.prop2 = 42 : 42 ->i.prop2 : 42 +>i.prop2 : string | number | boolean >i : One & Two & Three ->prop2 : 42 +>prop2 : string | number | boolean >42 : 42 -i.prop2 = "hello"; // error +i.prop2 = "hello"; >i.prop2 = "hello" : "hello" ->i.prop2 : 42 +>i.prop2 : string | number | boolean >i : One & Two & Three ->prop2 : 42 +>prop2 : string | number | boolean >"hello" : "hello" diff --git a/tests/baselines/reference/divergentAccessorsTypes8.errors.txt b/tests/baselines/reference/divergentAccessorsTypes8.errors.txt index ab22c1b5dd76d..e4a8e70a789e6 100644 --- a/tests/baselines/reference/divergentAccessorsTypes8.errors.txt +++ b/tests/baselines/reference/divergentAccessorsTypes8.errors.txt @@ -1,13 +1,16 @@ divergentAccessorsTypes8.ts(20,1): error TS2322: Type 'CSSStyleDeclaration' is not assignable to type 'string'. -divergentAccessorsTypes8.ts(86,1): error TS2322: Type 'number' is not assignable to type 'string'. -divergentAccessorsTypes8.ts(124,1): error TS2322: Type '42' is not assignable to type '"hello"'. -divergentAccessorsTypes8.ts(128,1): error TS2322: Type '"hello"' is not assignable to type '42'. +divergentAccessorsTypes8.ts(68,1): error TS2322: Type 'number' is not assignable to type 'string'. +divergentAccessorsTypes8.ts(71,1): error TS2322: Type 'number' is not assignable to type 'never'. +divergentAccessorsTypes8.ts(72,1): error TS2322: Type 'string' is not assignable to type 'never'. +divergentAccessorsTypes8.ts(73,1): error TS2322: Type 'boolean' is not assignable to type 'never'. +divergentAccessorsTypes8.ts(75,1): error TS2322: Type 'number' is not assignable to type 'string'. +divergentAccessorsTypes8.ts(77,1): error TS2322: Type 'boolean' is not assignable to type 'string'. divergentAccessorsTypes8.ts(146,1): error TS2322: Type 'number' is not assignable to type 'boolean'. divergentAccessorsTypes8.ts(148,1): error TS2322: Type 'string' is not assignable to type 'boolean'. divergentAccessorsTypes8.ts(149,1): error TS2322: Type 'null' is not assignable to type 'boolean'. -==== divergentAccessorsTypes8.ts (7 errors) ==== +==== divergentAccessorsTypes8.ts (10 errors) ==== export {} interface Serializer { @@ -78,15 +81,27 @@ divergentAccessorsTypes8.ts(149,1): error TS2322: Type 'null' is not assignable u1['prop1'] = "hello"; u1['prop2'] = 42; + ~~~~~~~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. u1['prop2'] = "hello"; u1['prop3'] = 42; + ~~~~~~~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'never'. u1['prop3'] = "hello"; + ~~~~~~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type 'never'. u1['prop3'] = true; + ~~~~~~~~~~~ +!!! error TS2322: Type 'boolean' is not assignable to type 'never'. u1['prop4'] = 42; + ~~~~~~~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. u1['prop4'] = "hello"; u1['prop4'] = true; + ~~~~~~~~~~~ +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. declare const i: One & Two; @@ -96,8 +111,6 @@ divergentAccessorsTypes8.ts(149,1): error TS2322: Type 'null' is not assignable const iv2 = i['prop2']; i['prop2'] = 42; - ~~~~~~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'string'. i['prop2'] = "hello"; class Three { @@ -136,14 +149,10 @@ divergentAccessorsTypes8.ts(149,1): error TS2322: Type 'null' is not assignable declare const i2: Three & Four & Five; i2['prop1'] = 42; - ~~~~~~~~~~~ -!!! error TS2322: Type '42' is not assignable to type '"hello"'. i2['prop1'] = "hello"; i2['prop2'] = 42; i2['prop2'] = "hello"; - ~~~~~~~~~~~ -!!! error TS2322: Type '"hello"' is not assignable to type '42'. class Six { get prop1(): boolean | number { diff --git a/tests/baselines/reference/divergentAccessorsTypes8.types b/tests/baselines/reference/divergentAccessorsTypes8.types index d847385f38ffd..3c09931b5c893 100644 --- a/tests/baselines/reference/divergentAccessorsTypes8.types +++ b/tests/baselines/reference/divergentAccessorsTypes8.types @@ -170,56 +170,56 @@ u1['prop1'] = "hello"; u1['prop2'] = 42; >u1['prop2'] = 42 : 42 ->u1['prop2'] : string | number +>u1['prop2'] : string >u1 : One | Two >'prop2' : "prop2" >42 : 42 u1['prop2'] = "hello"; >u1['prop2'] = "hello" : "hello" ->u1['prop2'] : string | number +>u1['prop2'] : string >u1 : One | Two >'prop2' : "prop2" >"hello" : "hello" u1['prop3'] = 42; >u1['prop3'] = 42 : 42 ->u1['prop3'] : string | number | boolean +>u1['prop3'] : never >u1 : One | Two >'prop3' : "prop3" >42 : 42 u1['prop3'] = "hello"; >u1['prop3'] = "hello" : "hello" ->u1['prop3'] : string | number | boolean +>u1['prop3'] : never >u1 : One | Two >'prop3' : "prop3" >"hello" : "hello" u1['prop3'] = true; >u1['prop3'] = true : true ->u1['prop3'] : string | number | boolean +>u1['prop3'] : never >u1 : One | Two >'prop3' : "prop3" >true : true u1['prop4'] = 42; >u1['prop4'] = 42 : 42 ->u1['prop4'] : string | number | boolean +>u1['prop4'] : string >u1 : One | Two >'prop4' : "prop4" >42 : 42 u1['prop4'] = "hello"; >u1['prop4'] = "hello" : "hello" ->u1['prop4'] : string | number | boolean +>u1['prop4'] : string >u1 : One | Two >'prop4' : "prop4" >"hello" : "hello" u1['prop4'] = true; >u1['prop4'] = true : true ->u1['prop4'] : string | number | boolean +>u1['prop4'] : string >u1 : One | Two >'prop4' : "prop4" >true : true @@ -255,14 +255,14 @@ const iv2 = i['prop2']; i['prop2'] = 42; >i['prop2'] = 42 : 42 ->i['prop2'] : string +>i['prop2'] : string | number >i : One & Two >'prop2' : "prop2" >42 : 42 i['prop2'] = "hello"; >i['prop2'] = "hello" : "hello" ->i['prop2'] : string +>i['prop2'] : string | number >i : One & Two >'prop2' : "prop2" >"hello" : "hello" @@ -338,28 +338,28 @@ declare const i2: Three & Four & Five; i2['prop1'] = 42; >i2['prop1'] = 42 : 42 ->i2['prop1'] : "hello" +>i2['prop1'] : string | number | boolean >i2 : Three & Four & Five >'prop1' : "prop1" >42 : 42 i2['prop1'] = "hello"; >i2['prop1'] = "hello" : "hello" ->i2['prop1'] : "hello" +>i2['prop1'] : string | number | boolean >i2 : Three & Four & Five >'prop1' : "prop1" >"hello" : "hello" i2['prop2'] = 42; >i2['prop2'] = 42 : 42 ->i2['prop2'] : 42 +>i2['prop2'] : string | number | boolean >i2 : Three & Four & Five >'prop2' : "prop2" >42 : 42 i2['prop2'] = "hello"; >i2['prop2'] = "hello" : "hello" ->i2['prop2'] : 42 +>i2['prop2'] : string | number | boolean >i2 : Three & Four & Five >'prop2' : "prop2" >"hello" : "hello" diff --git a/tests/cases/compiler/-da/divergentAccessorsTypes-56894-a.ts b/tests/cases/compiler/-da/divergentAccessorsTypes-56894-a.ts new file mode 100644 index 0000000000000..af4ac949aec89 --- /dev/null +++ b/tests/cases/compiler/-da/divergentAccessorsTypes-56894-a.ts @@ -0,0 +1,27 @@ +// @strict: true +// @declaration: true +// @target: esnext + +declare const id:()=>T + +function f2(x: {f:((a:1|2)=>1|2)} | {f:((a:2|3)=>2|3)} ){ + const r = x.f(id()) +// ^ const id: <2>() => 2, +// ^ const r: 1 | 2 | 3 +} + +function f3(f: ((a:1|2)=>1|2) | ((a:2|3)=>2|3) ){ + const r = f(id()) +// ^ const id: <2>() => 2, +// ^ const r: 1 | 2 | 3 +} + + +function f4(x: {set d(a:1|2); get r():1|2} | {set d(a:2|3); get r():2|3} ){ +// ^ (parameter) x: { d: 1 | 2; readonly r: 1 | 2; } | { d: 2 | 3; readonly r: 2 | 3; } + x.d = id(); +// ^ const id: <1 | 2 | 3>() => 1 | 2 | 3 (5.3.2) +// ^ const id: <2>() => 2 (expecting, if a setter was treated as a function) + x.r; +// ^ (property) r: 1 | 2 | 3 +} \ No newline at end of file diff --git a/tests/cases/compiler/-da/divergentAccessorsTypes-56894-b.ts b/tests/cases/compiler/-da/divergentAccessorsTypes-56894-b.ts new file mode 100644 index 0000000000000..9ab3bda1b30b5 --- /dev/null +++ b/tests/cases/compiler/-da/divergentAccessorsTypes-56894-b.ts @@ -0,0 +1,44 @@ + +type T12 = { + a: 1|2; + set gsa(x: 1|2); + get gsa(): 1|2; + set sb(x: 1|2); + get gc(): 1|2; +}; +type T23 = { + a: 2|3; + set gsa(x: 2|3); + get gsa(): 2|3; + set sb(x: 2|3); + get gc(): 2|3; +}; + +function fu(u:T12|T23) { + u.a = 1; + u.sb = 1; + u.gsa = 1; + u.a = 2; + u.sb = 2; + u.gsa = 2; + u.a = 3; + u.sb = 3; + u.gsa = 3; + if (u.gsa === 1) { + u.gsa; + } + if (u.gc === 1) { + u.gc; + } +} +function fi(i:T12&T23) { + i.a = 1; // error before & after + i.sb = 1; // error before & after + i.gsa = 1; // error before & after + if (i.gsa === 1) { // error before & after + i.gsa; + } + if (i.gc === 1) { // error before & after + i.gc; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/divergentAccessorsTypes4.ts b/tests/cases/compiler/divergentAccessorsTypes4.ts index 802a1b4d2c63c..e4f188f6ff050 100644 --- a/tests/cases/compiler/divergentAccessorsTypes4.ts +++ b/tests/cases/compiler/divergentAccessorsTypes4.ts @@ -20,12 +20,12 @@ declare const i: One & Two; // "hello" i.prop1; -// number | "hello" +// string | number i.prop1 = 42; i.prop1 = "hello"; // never i.prop2; -// 42 +// string | number i.prop2 = 42; -i.prop2 = "hello"; // error +i.prop2 = "hello"; diff --git a/tests/cases/compiler/divergentAccessorsTypes5.ts b/tests/cases/compiler/divergentAccessorsTypes5.ts index 54d1099004a17..f59ad05220773 100644 --- a/tests/cases/compiler/divergentAccessorsTypes5.ts +++ b/tests/cases/compiler/divergentAccessorsTypes5.ts @@ -30,9 +30,9 @@ class Three { declare const i: One & Two & Three; // "hello" -i.prop1 = 42; // error +i.prop1 = 42; i.prop1 = "hello"; // 42 i.prop2 = 42; -i.prop2 = "hello"; // error +i.prop2 = "hello";