217 lines
3.7 KiB
Plaintext
217 lines
3.7 KiB
Plaintext
=== tests/cases/compiler/instanceOfAssignability.ts ===
|
|
interface Base {
|
|
>Base : Base
|
|
|
|
foo: string|number;
|
|
>foo : string | number
|
|
|
|
optional?: number;
|
|
>optional : number
|
|
}
|
|
|
|
// Derived1 is assignable to, but not a subtype of, Base
|
|
class Derived1 implements Base {
|
|
>Derived1 : Derived1
|
|
>Base : Base
|
|
|
|
foo: string;
|
|
>foo : string
|
|
}
|
|
// Derived2 is a subtype of Base that is not assignable to Derived1
|
|
class Derived2 implements Base {
|
|
>Derived2 : Derived2
|
|
>Base : Base
|
|
|
|
foo: number;
|
|
>foo : number
|
|
|
|
optional: number;
|
|
>optional : number
|
|
}
|
|
|
|
class Animal {
|
|
>Animal : Animal
|
|
|
|
move;
|
|
>move : any
|
|
}
|
|
class Mammal extends Animal { milk; }
|
|
>Mammal : Mammal
|
|
>Animal : Animal
|
|
>milk : any
|
|
|
|
class Giraffe extends Mammal { neck; }
|
|
>Giraffe : Giraffe
|
|
>Mammal : Mammal
|
|
>neck : any
|
|
|
|
function fn1(x: Array<number>|Array<string>|boolean) {
|
|
>fn1 : (x: number[] | string[] | boolean) => void
|
|
>x : number[] | string[] | boolean
|
|
>Array : T[]
|
|
>Array : T[]
|
|
|
|
if(x instanceof Array) {
|
|
>x instanceof Array : boolean
|
|
>x : number[] | string[] | boolean
|
|
>Array : ArrayConstructor
|
|
|
|
// 1.5: y: Array<number>|Array<string>
|
|
// Want: y: Array<number>|Array<string>
|
|
let y = x;
|
|
>y : number[] | string[]
|
|
>x : number[] | string[]
|
|
}
|
|
}
|
|
|
|
function fn2(x: Base) {
|
|
>fn2 : (x: Base) => void
|
|
>x : Base
|
|
>Base : Base
|
|
|
|
if(x instanceof Derived1) {
|
|
>x instanceof Derived1 : boolean
|
|
>x : Base
|
|
>Derived1 : typeof Derived1
|
|
|
|
// 1.5: y: Base
|
|
// Want: y: Derived1
|
|
let y = x;
|
|
>y : Derived1
|
|
>x : Derived1
|
|
}
|
|
}
|
|
|
|
function fn3(x: Base|Derived1) {
|
|
>fn3 : (x: Base | Derived1) => void
|
|
>x : Base | Derived1
|
|
>Base : Base
|
|
>Derived1 : Derived1
|
|
|
|
if(x instanceof Derived2) {
|
|
>x instanceof Derived2 : boolean
|
|
>x : Base | Derived1
|
|
>Derived2 : typeof Derived2
|
|
|
|
// 1.5: y: Derived2
|
|
// Want: Derived2
|
|
let y = x;
|
|
>y : Derived2
|
|
>x : Derived2
|
|
}
|
|
}
|
|
|
|
function fn4(x: Base|Derived2) {
|
|
>fn4 : (x: Base | Derived2) => void
|
|
>x : Base | Derived2
|
|
>Base : Base
|
|
>Derived2 : Derived2
|
|
|
|
if(x instanceof Derived1) {
|
|
>x instanceof Derived1 : boolean
|
|
>x : Base | Derived2
|
|
>Derived1 : typeof Derived1
|
|
|
|
// 1.5: y: {}
|
|
// Want: Derived1
|
|
let y = x;
|
|
>y : Derived1
|
|
>x : Derived1
|
|
}
|
|
}
|
|
|
|
function fn5(x: Derived1) {
|
|
>fn5 : (x: Derived1) => void
|
|
>x : Derived1
|
|
>Derived1 : Derived1
|
|
|
|
if(x instanceof Derived2) {
|
|
>x instanceof Derived2 : boolean
|
|
>x : Derived1
|
|
>Derived2 : typeof Derived2
|
|
|
|
// 1.5: y: Derived1
|
|
// Want: ???
|
|
let y = x;
|
|
>y : Derived1
|
|
>x : Derived1
|
|
}
|
|
}
|
|
|
|
function fn6(x: Animal|Mammal) {
|
|
>fn6 : (x: Animal | Mammal) => void
|
|
>x : Animal | Mammal
|
|
>Animal : Animal
|
|
>Mammal : Mammal
|
|
|
|
if(x instanceof Giraffe) {
|
|
>x instanceof Giraffe : boolean
|
|
>x : Animal | Mammal
|
|
>Giraffe : typeof Giraffe
|
|
|
|
// 1.5: y: Derived1
|
|
// Want: ???
|
|
let y = x;
|
|
>y : Giraffe
|
|
>x : Giraffe
|
|
}
|
|
}
|
|
|
|
function fn7(x: Array<number>|Array<string>) {
|
|
>fn7 : (x: number[] | string[]) => void
|
|
>x : number[] | string[]
|
|
>Array : T[]
|
|
>Array : T[]
|
|
|
|
if(x instanceof Array) {
|
|
>x instanceof Array : boolean
|
|
>x : number[] | string[]
|
|
>Array : ArrayConstructor
|
|
|
|
// 1.5: y: Array<number>|Array<string>
|
|
// Want: y: Array<number>|Array<string>
|
|
let y = x;
|
|
>y : number[] | string[]
|
|
>x : number[] | string[]
|
|
}
|
|
}
|
|
|
|
interface Alpha { a }
|
|
>Alpha : Alpha
|
|
>a : any
|
|
|
|
interface Beta { b }
|
|
>Beta : Beta
|
|
>b : any
|
|
|
|
interface Gamma { c }
|
|
>Gamma : Gamma
|
|
>c : any
|
|
|
|
class ABC { a; b; c; }
|
|
>ABC : ABC
|
|
>a : any
|
|
>b : any
|
|
>c : any
|
|
|
|
function fn8(x: Alpha|Beta|Gamma) {
|
|
>fn8 : (x: Alpha | Beta | Gamma) => void
|
|
>x : Alpha | Beta | Gamma
|
|
>Alpha : Alpha
|
|
>Beta : Beta
|
|
>Gamma : Gamma
|
|
|
|
if(x instanceof ABC) {
|
|
>x instanceof ABC : boolean
|
|
>x : Alpha | Beta | Gamma
|
|
>ABC : typeof ABC
|
|
|
|
let y = x;
|
|
>y : ABC
|
|
>x : ABC
|
|
}
|
|
}
|
|
|
|
|
|
|