TypeScript/tests/baselines/reference/arrayLiteralContextualType.types

91 lines
3.7 KiB
Text
Raw Normal View History

2014-10-10 23:41:14 +02:00
=== tests/cases/compiler/arrayLiteralContextualType.ts ===
interface IAnimal {
>IAnimal : IAnimal, Symbol(IAnimal,Decl(arrayLiteralContextualType.ts,0,0))
2014-10-10 23:41:14 +02:00
name: string;
>name : string, Symbol(name,Decl(arrayLiteralContextualType.ts,0,19))
2014-10-10 23:41:14 +02:00
}
class Giraffe {
>Giraffe : Giraffe, Symbol(Giraffe,Decl(arrayLiteralContextualType.ts,2,1))
2014-10-10 23:41:14 +02:00
name = "Giraffe";
>name : string, Symbol(name,Decl(arrayLiteralContextualType.ts,4,15))
2015-04-13 21:36:11 +02:00
>"Giraffe" : string
2014-10-10 23:41:14 +02:00
neckLength = "3m";
>neckLength : string, Symbol(neckLength,Decl(arrayLiteralContextualType.ts,5,21))
2015-04-13 21:36:11 +02:00
>"3m" : string
2014-10-10 23:41:14 +02:00
}
class Elephant {
>Elephant : Elephant, Symbol(Elephant,Decl(arrayLiteralContextualType.ts,7,1))
2014-10-10 23:41:14 +02:00
name = "Elephant";
>name : string, Symbol(name,Decl(arrayLiteralContextualType.ts,9,16))
2015-04-13 21:36:11 +02:00
>"Elephant" : string
2014-10-10 23:41:14 +02:00
trunkDiameter = "20cm";
>trunkDiameter : string, Symbol(trunkDiameter,Decl(arrayLiteralContextualType.ts,10,22))
2015-04-13 21:36:11 +02:00
>"20cm" : string
2014-10-10 23:41:14 +02:00
}
function foo(animals: IAnimal[]) { }
>foo : (animals: IAnimal[]) => void, Symbol(foo,Decl(arrayLiteralContextualType.ts,12,1))
>animals : IAnimal[], Symbol(animals,Decl(arrayLiteralContextualType.ts,14,13))
>IAnimal : IAnimal, Symbol(IAnimal,Decl(arrayLiteralContextualType.ts,0,0))
2014-10-10 23:41:14 +02:00
function bar(animals: { [n: number]: IAnimal }) { }
>bar : (animals: { [n: number]: IAnimal; }) => void, Symbol(bar,Decl(arrayLiteralContextualType.ts,14,36))
>animals : { [n: number]: IAnimal; }, Symbol(animals,Decl(arrayLiteralContextualType.ts,15,13))
>n : number, Symbol(n,Decl(arrayLiteralContextualType.ts,15,25))
>IAnimal : IAnimal, Symbol(IAnimal,Decl(arrayLiteralContextualType.ts,0,0))
2014-10-10 23:41:14 +02:00
foo([
>foo([ new Giraffe(), new Elephant()]) : void
>foo : (animals: IAnimal[]) => void, Symbol(foo,Decl(arrayLiteralContextualType.ts,12,1))
>[ new Giraffe(), new Elephant()] : (Giraffe | Elephant)[]
2014-10-10 23:41:14 +02:00
new Giraffe(),
>new Giraffe() : Giraffe
>Giraffe : typeof Giraffe, Symbol(Giraffe,Decl(arrayLiteralContextualType.ts,2,1))
2014-10-10 23:41:14 +02:00
new Elephant()
>new Elephant() : Elephant
>Elephant : typeof Elephant, Symbol(Elephant,Decl(arrayLiteralContextualType.ts,7,1))
2014-10-10 23:41:14 +02:00
]); // Legal because of the contextual type IAnimal provided by the parameter
bar([
>bar([ new Giraffe(), new Elephant()]) : void
>bar : (animals: { [n: number]: IAnimal; }) => void, Symbol(bar,Decl(arrayLiteralContextualType.ts,14,36))
>[ new Giraffe(), new Elephant()] : (Giraffe | Elephant)[]
2014-10-10 23:41:14 +02:00
new Giraffe(),
>new Giraffe() : Giraffe
>Giraffe : typeof Giraffe, Symbol(Giraffe,Decl(arrayLiteralContextualType.ts,2,1))
2014-10-10 23:41:14 +02:00
new Elephant()
>new Elephant() : Elephant
>Elephant : typeof Elephant, Symbol(Elephant,Decl(arrayLiteralContextualType.ts,7,1))
2014-10-10 23:41:14 +02:00
]); // Legal because of the contextual type IAnimal provided by the parameter
var arr = [new Giraffe(), new Elephant()];
>arr : (Giraffe | Elephant)[], Symbol(arr,Decl(arrayLiteralContextualType.ts,26,3))
>[new Giraffe(), new Elephant()] : (Giraffe | Elephant)[]
2014-10-10 23:41:14 +02:00
>new Giraffe() : Giraffe
>Giraffe : typeof Giraffe, Symbol(Giraffe,Decl(arrayLiteralContextualType.ts,2,1))
2014-10-10 23:41:14 +02:00
>new Elephant() : Elephant
>Elephant : typeof Elephant, Symbol(Elephant,Decl(arrayLiteralContextualType.ts,7,1))
2014-10-10 23:41:14 +02:00
foo(arr); // ok because arr is Array<Giraffe|Elephant> not {}[]
>foo(arr) : void
>foo : (animals: IAnimal[]) => void, Symbol(foo,Decl(arrayLiteralContextualType.ts,12,1))
>arr : (Giraffe | Elephant)[], Symbol(arr,Decl(arrayLiteralContextualType.ts,26,3))
2014-10-10 23:41:14 +02:00
bar(arr); // ok because arr is Array<Giraffe|Elephant> not {}[]
>bar(arr) : void
>bar : (animals: { [n: number]: IAnimal; }) => void, Symbol(bar,Decl(arrayLiteralContextualType.ts,14,36))
>arr : (Giraffe | Elephant)[], Symbol(arr,Decl(arrayLiteralContextualType.ts,26,3))
2014-10-10 23:41:14 +02:00