mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 23:08:20 -06:00
Adding regression test
This commit is contained in:
parent
bd4923a295
commit
644e987633
80
tests/baselines/reference/narrowingOfDottedNames.js
Normal file
80
tests/baselines/reference/narrowingOfDottedNames.js
Normal file
@ -0,0 +1,80 @@
|
||||
//// [narrowingOfDottedNames.ts]
|
||||
// Repro from #8383
|
||||
|
||||
class A {
|
||||
prop: { a: string; };
|
||||
}
|
||||
|
||||
class B {
|
||||
prop: { b: string; }
|
||||
}
|
||||
|
||||
function isA(x: any): x is A {
|
||||
return x instanceof A;
|
||||
}
|
||||
|
||||
function isB(x: any): x is B {
|
||||
return x instanceof B;
|
||||
}
|
||||
|
||||
function f1(x: A | B) {
|
||||
while (true) {
|
||||
if (x instanceof A) {
|
||||
x.prop.a;
|
||||
}
|
||||
else if (x instanceof B) {
|
||||
x.prop.b; // error: property 'b' doesn't exist on type { a: string }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f2(x: A | B) {
|
||||
while (true) {
|
||||
if (isA(x)) {
|
||||
x.prop.a;
|
||||
}
|
||||
else if (isB(x)) {
|
||||
x.prop.b; // error: property 'b' doesn't exist on type { a: string }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [narrowingOfDottedNames.js]
|
||||
// Repro from #8383
|
||||
var A = (function () {
|
||||
function A() {
|
||||
}
|
||||
return A;
|
||||
}());
|
||||
var B = (function () {
|
||||
function B() {
|
||||
}
|
||||
return B;
|
||||
}());
|
||||
function isA(x) {
|
||||
return x instanceof A;
|
||||
}
|
||||
function isB(x) {
|
||||
return x instanceof B;
|
||||
}
|
||||
function f1(x) {
|
||||
while (true) {
|
||||
if (x instanceof A) {
|
||||
x.prop.a;
|
||||
}
|
||||
else if (x instanceof B) {
|
||||
x.prop.b; // error: property 'b' doesn't exist on type { a: string }
|
||||
}
|
||||
}
|
||||
}
|
||||
function f2(x) {
|
||||
while (true) {
|
||||
if (isA(x)) {
|
||||
x.prop.a;
|
||||
}
|
||||
else if (isB(x)) {
|
||||
x.prop.b; // error: property 'b' doesn't exist on type { a: string }
|
||||
}
|
||||
}
|
||||
}
|
||||
105
tests/baselines/reference/narrowingOfDottedNames.symbols
Normal file
105
tests/baselines/reference/narrowingOfDottedNames.symbols
Normal file
@ -0,0 +1,105 @@
|
||||
=== tests/cases/compiler/narrowingOfDottedNames.ts ===
|
||||
// Repro from #8383
|
||||
|
||||
class A {
|
||||
>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0))
|
||||
|
||||
prop: { a: string; };
|
||||
>prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9))
|
||||
>a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11))
|
||||
}
|
||||
|
||||
class B {
|
||||
>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1))
|
||||
|
||||
prop: { b: string; }
|
||||
>prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9))
|
||||
>b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11))
|
||||
}
|
||||
|
||||
function isA(x: any): x is A {
|
||||
>isA : Symbol(isA, Decl(narrowingOfDottedNames.ts, 8, 1))
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 10, 13))
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 10, 13))
|
||||
>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0))
|
||||
|
||||
return x instanceof A;
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 10, 13))
|
||||
>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0))
|
||||
}
|
||||
|
||||
function isB(x: any): x is B {
|
||||
>isB : Symbol(isB, Decl(narrowingOfDottedNames.ts, 12, 1))
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 14, 13))
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 14, 13))
|
||||
>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1))
|
||||
|
||||
return x instanceof B;
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 14, 13))
|
||||
>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1))
|
||||
}
|
||||
|
||||
function f1(x: A | B) {
|
||||
>f1 : Symbol(f1, Decl(narrowingOfDottedNames.ts, 16, 1))
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12))
|
||||
>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1))
|
||||
|
||||
while (true) {
|
||||
if (x instanceof A) {
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12))
|
||||
>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0))
|
||||
|
||||
x.prop.a;
|
||||
>x.prop.a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11))
|
||||
>x.prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9))
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12))
|
||||
>prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9))
|
||||
>a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11))
|
||||
}
|
||||
else if (x instanceof B) {
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12))
|
||||
>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1))
|
||||
|
||||
x.prop.b; // error: property 'b' doesn't exist on type { a: string }
|
||||
>x.prop.b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11))
|
||||
>x.prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9))
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 18, 12))
|
||||
>prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9))
|
||||
>b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f2(x: A | B) {
|
||||
>f2 : Symbol(f2, Decl(narrowingOfDottedNames.ts, 27, 1))
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12))
|
||||
>A : Symbol(A, Decl(narrowingOfDottedNames.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(narrowingOfDottedNames.ts, 4, 1))
|
||||
|
||||
while (true) {
|
||||
if (isA(x)) {
|
||||
>isA : Symbol(isA, Decl(narrowingOfDottedNames.ts, 8, 1))
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12))
|
||||
|
||||
x.prop.a;
|
||||
>x.prop.a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11))
|
||||
>x.prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9))
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12))
|
||||
>prop : Symbol(A.prop, Decl(narrowingOfDottedNames.ts, 2, 9))
|
||||
>a : Symbol(a, Decl(narrowingOfDottedNames.ts, 3, 11))
|
||||
}
|
||||
else if (isB(x)) {
|
||||
>isB : Symbol(isB, Decl(narrowingOfDottedNames.ts, 12, 1))
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12))
|
||||
|
||||
x.prop.b; // error: property 'b' doesn't exist on type { a: string }
|
||||
>x.prop.b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11))
|
||||
>x.prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9))
|
||||
>x : Symbol(x, Decl(narrowingOfDottedNames.ts, 29, 12))
|
||||
>prop : Symbol(B.prop, Decl(narrowingOfDottedNames.ts, 6, 9))
|
||||
>b : Symbol(b, Decl(narrowingOfDottedNames.ts, 7, 11))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
115
tests/baselines/reference/narrowingOfDottedNames.types
Normal file
115
tests/baselines/reference/narrowingOfDottedNames.types
Normal file
@ -0,0 +1,115 @@
|
||||
=== tests/cases/compiler/narrowingOfDottedNames.ts ===
|
||||
// Repro from #8383
|
||||
|
||||
class A {
|
||||
>A : A
|
||||
|
||||
prop: { a: string; };
|
||||
>prop : { a: string; }
|
||||
>a : string
|
||||
}
|
||||
|
||||
class B {
|
||||
>B : B
|
||||
|
||||
prop: { b: string; }
|
||||
>prop : { b: string; }
|
||||
>b : string
|
||||
}
|
||||
|
||||
function isA(x: any): x is A {
|
||||
>isA : (x: any) => x is A
|
||||
>x : any
|
||||
>x : any
|
||||
>A : A
|
||||
|
||||
return x instanceof A;
|
||||
>x instanceof A : boolean
|
||||
>x : any
|
||||
>A : typeof A
|
||||
}
|
||||
|
||||
function isB(x: any): x is B {
|
||||
>isB : (x: any) => x is B
|
||||
>x : any
|
||||
>x : any
|
||||
>B : B
|
||||
|
||||
return x instanceof B;
|
||||
>x instanceof B : boolean
|
||||
>x : any
|
||||
>B : typeof B
|
||||
}
|
||||
|
||||
function f1(x: A | B) {
|
||||
>f1 : (x: A | B) => void
|
||||
>x : A | B
|
||||
>A : A
|
||||
>B : B
|
||||
|
||||
while (true) {
|
||||
>true : boolean
|
||||
|
||||
if (x instanceof A) {
|
||||
>x instanceof A : boolean
|
||||
>x : A | B
|
||||
>A : typeof A
|
||||
|
||||
x.prop.a;
|
||||
>x.prop.a : string
|
||||
>x.prop : { a: string; }
|
||||
>x : A
|
||||
>prop : { a: string; }
|
||||
>a : string
|
||||
}
|
||||
else if (x instanceof B) {
|
||||
>x instanceof B : boolean
|
||||
>x : B
|
||||
>B : typeof B
|
||||
|
||||
x.prop.b; // error: property 'b' doesn't exist on type { a: string }
|
||||
>x.prop.b : string
|
||||
>x.prop : { b: string; }
|
||||
>x : B
|
||||
>prop : { b: string; }
|
||||
>b : string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f2(x: A | B) {
|
||||
>f2 : (x: A | B) => void
|
||||
>x : A | B
|
||||
>A : A
|
||||
>B : B
|
||||
|
||||
while (true) {
|
||||
>true : boolean
|
||||
|
||||
if (isA(x)) {
|
||||
>isA(x) : boolean
|
||||
>isA : (x: any) => x is A
|
||||
>x : A | B
|
||||
|
||||
x.prop.a;
|
||||
>x.prop.a : string
|
||||
>x.prop : { a: string; }
|
||||
>x : A
|
||||
>prop : { a: string; }
|
||||
>a : string
|
||||
}
|
||||
else if (isB(x)) {
|
||||
>isB(x) : boolean
|
||||
>isB : (x: any) => x is B
|
||||
>x : B
|
||||
|
||||
x.prop.b; // error: property 'b' doesn't exist on type { a: string }
|
||||
>x.prop.b : string
|
||||
>x.prop : { b: string; }
|
||||
>x : B
|
||||
>prop : { b: string; }
|
||||
>b : string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
39
tests/cases/compiler/narrowingOfDottedNames.ts
Normal file
39
tests/cases/compiler/narrowingOfDottedNames.ts
Normal file
@ -0,0 +1,39 @@
|
||||
// Repro from #8383
|
||||
|
||||
class A {
|
||||
prop: { a: string; };
|
||||
}
|
||||
|
||||
class B {
|
||||
prop: { b: string; }
|
||||
}
|
||||
|
||||
function isA(x: any): x is A {
|
||||
return x instanceof A;
|
||||
}
|
||||
|
||||
function isB(x: any): x is B {
|
||||
return x instanceof B;
|
||||
}
|
||||
|
||||
function f1(x: A | B) {
|
||||
while (true) {
|
||||
if (x instanceof A) {
|
||||
x.prop.a;
|
||||
}
|
||||
else if (x instanceof B) {
|
||||
x.prop.b; // error: property 'b' doesn't exist on type { a: string }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function f2(x: A | B) {
|
||||
while (true) {
|
||||
if (isA(x)) {
|
||||
x.prop.a;
|
||||
}
|
||||
else if (isB(x)) {
|
||||
x.prop.b; // error: property 'b' doesn't exist on type { a: string }
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user