mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-14 15:33:32 -06:00
Add a regression test
This commit is contained in:
parent
8b43b3d18c
commit
42b56cf671
53
tests/baselines/reference/narrowTypeByInstanceof.js
Normal file
53
tests/baselines/reference/narrowTypeByInstanceof.js
Normal file
@ -0,0 +1,53 @@
|
||||
//// [narrowTypeByInstanceof.ts]
|
||||
class Match {
|
||||
public range(): any {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
class FileMatch {
|
||||
public resource(): any {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
type FileMatchOrMatch = FileMatch | Match;
|
||||
|
||||
|
||||
let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch;
|
||||
|
||||
if (elementA instanceof FileMatch && elementB instanceof FileMatch) {
|
||||
let a = elementA.resource().path;
|
||||
let b = elementB.resource().path;
|
||||
} else if (elementA instanceof Match && elementB instanceof Match) {
|
||||
let a = elementA.range();
|
||||
let b = elementB.range();
|
||||
}
|
||||
|
||||
|
||||
//// [narrowTypeByInstanceof.js]
|
||||
var Match = (function () {
|
||||
function Match() {
|
||||
}
|
||||
Match.prototype.range = function () {
|
||||
return undefined;
|
||||
};
|
||||
return Match;
|
||||
})();
|
||||
var FileMatch = (function () {
|
||||
function FileMatch() {
|
||||
}
|
||||
FileMatch.prototype.resource = function () {
|
||||
return undefined;
|
||||
};
|
||||
return FileMatch;
|
||||
})();
|
||||
var elementA, elementB;
|
||||
if (elementA instanceof FileMatch && elementB instanceof FileMatch) {
|
||||
var a = elementA.resource().path;
|
||||
var b = elementB.resource().path;
|
||||
}
|
||||
else if (elementA instanceof Match && elementB instanceof Match) {
|
||||
var a = elementA.range();
|
||||
var b = elementB.range();
|
||||
}
|
||||
72
tests/baselines/reference/narrowTypeByInstanceof.symbols
Normal file
72
tests/baselines/reference/narrowTypeByInstanceof.symbols
Normal file
@ -0,0 +1,72 @@
|
||||
=== tests/cases/compiler/narrowTypeByInstanceof.ts ===
|
||||
class Match {
|
||||
>Match : Symbol(Match, Decl(narrowTypeByInstanceof.ts, 0, 0))
|
||||
|
||||
public range(): any {
|
||||
>range : Symbol(range, Decl(narrowTypeByInstanceof.ts, 0, 17))
|
||||
|
||||
return undefined;
|
||||
>undefined : Symbol(undefined)
|
||||
}
|
||||
}
|
||||
|
||||
class FileMatch {
|
||||
>FileMatch : Symbol(FileMatch, Decl(narrowTypeByInstanceof.ts, 4, 5))
|
||||
|
||||
public resource(): any {
|
||||
>resource : Symbol(resource, Decl(narrowTypeByInstanceof.ts, 6, 21))
|
||||
|
||||
return undefined;
|
||||
>undefined : Symbol(undefined)
|
||||
}
|
||||
}
|
||||
|
||||
type FileMatchOrMatch = FileMatch | Match;
|
||||
>FileMatchOrMatch : Symbol(FileMatchOrMatch, Decl(narrowTypeByInstanceof.ts, 10, 5))
|
||||
>FileMatch : Symbol(FileMatch, Decl(narrowTypeByInstanceof.ts, 4, 5))
|
||||
>Match : Symbol(Match, Decl(narrowTypeByInstanceof.ts, 0, 0))
|
||||
|
||||
|
||||
let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch;
|
||||
>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3))
|
||||
>FileMatchOrMatch : Symbol(FileMatchOrMatch, Decl(narrowTypeByInstanceof.ts, 10, 5))
|
||||
>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31))
|
||||
>FileMatchOrMatch : Symbol(FileMatchOrMatch, Decl(narrowTypeByInstanceof.ts, 10, 5))
|
||||
|
||||
if (elementA instanceof FileMatch && elementB instanceof FileMatch) {
|
||||
>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3))
|
||||
>FileMatch : Symbol(FileMatch, Decl(narrowTypeByInstanceof.ts, 4, 5))
|
||||
>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31))
|
||||
>FileMatch : Symbol(FileMatch, Decl(narrowTypeByInstanceof.ts, 4, 5))
|
||||
|
||||
let a = elementA.resource().path;
|
||||
>a : Symbol(a, Decl(narrowTypeByInstanceof.ts, 18, 7))
|
||||
>elementA.resource : Symbol(FileMatch.resource, Decl(narrowTypeByInstanceof.ts, 6, 21))
|
||||
>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3))
|
||||
>resource : Symbol(FileMatch.resource, Decl(narrowTypeByInstanceof.ts, 6, 21))
|
||||
|
||||
let b = elementB.resource().path;
|
||||
>b : Symbol(b, Decl(narrowTypeByInstanceof.ts, 19, 7))
|
||||
>elementB.resource : Symbol(FileMatch.resource, Decl(narrowTypeByInstanceof.ts, 6, 21))
|
||||
>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31))
|
||||
>resource : Symbol(FileMatch.resource, Decl(narrowTypeByInstanceof.ts, 6, 21))
|
||||
|
||||
} else if (elementA instanceof Match && elementB instanceof Match) {
|
||||
>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3))
|
||||
>Match : Symbol(Match, Decl(narrowTypeByInstanceof.ts, 0, 0))
|
||||
>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31))
|
||||
>Match : Symbol(Match, Decl(narrowTypeByInstanceof.ts, 0, 0))
|
||||
|
||||
let a = elementA.range();
|
||||
>a : Symbol(a, Decl(narrowTypeByInstanceof.ts, 21, 7))
|
||||
>elementA.range : Symbol(Match.range, Decl(narrowTypeByInstanceof.ts, 0, 17))
|
||||
>elementA : Symbol(elementA, Decl(narrowTypeByInstanceof.ts, 15, 3))
|
||||
>range : Symbol(Match.range, Decl(narrowTypeByInstanceof.ts, 0, 17))
|
||||
|
||||
let b = elementB.range();
|
||||
>b : Symbol(b, Decl(narrowTypeByInstanceof.ts, 22, 7))
|
||||
>elementB.range : Symbol(Match.range, Decl(narrowTypeByInstanceof.ts, 0, 17))
|
||||
>elementB : Symbol(elementB, Decl(narrowTypeByInstanceof.ts, 15, 31))
|
||||
>range : Symbol(Match.range, Decl(narrowTypeByInstanceof.ts, 0, 17))
|
||||
}
|
||||
|
||||
86
tests/baselines/reference/narrowTypeByInstanceof.types
Normal file
86
tests/baselines/reference/narrowTypeByInstanceof.types
Normal file
@ -0,0 +1,86 @@
|
||||
=== tests/cases/compiler/narrowTypeByInstanceof.ts ===
|
||||
class Match {
|
||||
>Match : Match
|
||||
|
||||
public range(): any {
|
||||
>range : () => any
|
||||
|
||||
return undefined;
|
||||
>undefined : undefined
|
||||
}
|
||||
}
|
||||
|
||||
class FileMatch {
|
||||
>FileMatch : FileMatch
|
||||
|
||||
public resource(): any {
|
||||
>resource : () => any
|
||||
|
||||
return undefined;
|
||||
>undefined : undefined
|
||||
}
|
||||
}
|
||||
|
||||
type FileMatchOrMatch = FileMatch | Match;
|
||||
>FileMatchOrMatch : Match | FileMatch
|
||||
>FileMatch : FileMatch
|
||||
>Match : Match
|
||||
|
||||
|
||||
let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch;
|
||||
>elementA : Match | FileMatch
|
||||
>FileMatchOrMatch : Match | FileMatch
|
||||
>elementB : Match | FileMatch
|
||||
>FileMatchOrMatch : Match | FileMatch
|
||||
|
||||
if (elementA instanceof FileMatch && elementB instanceof FileMatch) {
|
||||
>elementA instanceof FileMatch && elementB instanceof FileMatch : boolean
|
||||
>elementA instanceof FileMatch : boolean
|
||||
>elementA : Match | FileMatch
|
||||
>FileMatch : typeof FileMatch
|
||||
>elementB instanceof FileMatch : boolean
|
||||
>elementB : Match | FileMatch
|
||||
>FileMatch : typeof FileMatch
|
||||
|
||||
let a = elementA.resource().path;
|
||||
>a : any
|
||||
>elementA.resource().path : any
|
||||
>elementA.resource() : any
|
||||
>elementA.resource : () => any
|
||||
>elementA : FileMatch
|
||||
>resource : () => any
|
||||
>path : any
|
||||
|
||||
let b = elementB.resource().path;
|
||||
>b : any
|
||||
>elementB.resource().path : any
|
||||
>elementB.resource() : any
|
||||
>elementB.resource : () => any
|
||||
>elementB : FileMatch
|
||||
>resource : () => any
|
||||
>path : any
|
||||
|
||||
} else if (elementA instanceof Match && elementB instanceof Match) {
|
||||
>elementA instanceof Match && elementB instanceof Match : boolean
|
||||
>elementA instanceof Match : boolean
|
||||
>elementA : Match | FileMatch
|
||||
>Match : typeof Match
|
||||
>elementB instanceof Match : boolean
|
||||
>elementB : Match | FileMatch
|
||||
>Match : typeof Match
|
||||
|
||||
let a = elementA.range();
|
||||
>a : any
|
||||
>elementA.range() : any
|
||||
>elementA.range : () => any
|
||||
>elementA : Match
|
||||
>range : () => any
|
||||
|
||||
let b = elementB.range();
|
||||
>b : any
|
||||
>elementB.range() : any
|
||||
>elementB.range : () => any
|
||||
>elementB : Match
|
||||
>range : () => any
|
||||
}
|
||||
|
||||
24
tests/cases/compiler/narrowTypeByInstanceof.ts
Normal file
24
tests/cases/compiler/narrowTypeByInstanceof.ts
Normal file
@ -0,0 +1,24 @@
|
||||
class Match {
|
||||
public range(): any {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
class FileMatch {
|
||||
public resource(): any {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
type FileMatchOrMatch = FileMatch | Match;
|
||||
|
||||
|
||||
let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch;
|
||||
|
||||
if (elementA instanceof FileMatch && elementB instanceof FileMatch) {
|
||||
let a = elementA.resource().path;
|
||||
let b = elementB.resource().path;
|
||||
} else if (elementA instanceof Match && elementB instanceof Match) {
|
||||
let a = elementA.range();
|
||||
let b = elementB.range();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user