2014-10-10 23:41:14 +02:00
|
|
|
=== tests/cases/compiler/arrayLiteralContextualType.ts ===
|
|
|
|
interface IAnimal {
|
2015-04-13 22:54:22 +02:00
|
|
|
>IAnimal : IAnimal, Symbol(IAnimal,Decl(arrayLiteralContextualType.ts,0,0))
|
2014-10-10 23:41:14 +02:00
|
|
|
|
|
|
|
name: string;
|
2015-04-13 22:54:22 +02:00
|
|
|
>name : string, Symbol(name,Decl(arrayLiteralContextualType.ts,0,19))
|
2014-10-10 23:41:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class Giraffe {
|
2015-04-13 22:54:22 +02:00
|
|
|
>Giraffe : Giraffe, Symbol(Giraffe,Decl(arrayLiteralContextualType.ts,2,1))
|
2014-10-10 23:41:14 +02:00
|
|
|
|
|
|
|
name = "Giraffe";
|
2015-04-13 22:54:22 +02:00
|
|
|
>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";
|
2015-04-13 22:54:22 +02:00
|
|
|
>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 {
|
2015-04-13 22:54:22 +02:00
|
|
|
>Elephant : Elephant, Symbol(Elephant,Decl(arrayLiteralContextualType.ts,7,1))
|
2014-10-10 23:41:14 +02:00
|
|
|
|
|
|
|
name = "Elephant";
|
2015-04-13 22:54:22 +02:00
|
|
|
>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";
|
2015-04-13 22:54:22 +02:00
|
|
|
>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[]) { }
|
2015-04-13 22:54:22 +02:00
|
|
|
>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 }) { }
|
2015-04-13 22:54:22 +02:00
|
|
|
>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
|
2015-04-13 22:54:22 +02:00
|
|
|
>foo : (animals: IAnimal[]) => void, Symbol(foo,Decl(arrayLiteralContextualType.ts,12,1))
|
2014-10-18 01:53:18 +02:00
|
|
|
>[ new Giraffe(), new Elephant()] : (Giraffe | Elephant)[]
|
2014-10-10 23:41:14 +02:00
|
|
|
|
|
|
|
new Giraffe(),
|
|
|
|
>new Giraffe() : Giraffe
|
2015-04-13 22:54:22 +02:00
|
|
|
>Giraffe : typeof Giraffe, Symbol(Giraffe,Decl(arrayLiteralContextualType.ts,2,1))
|
2014-10-10 23:41:14 +02:00
|
|
|
|
|
|
|
new Elephant()
|
|
|
|
>new Elephant() : Elephant
|
2015-04-13 22:54:22 +02:00
|
|
|
>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
|
2015-04-13 22:54:22 +02:00
|
|
|
>bar : (animals: { [n: number]: IAnimal; }) => void, Symbol(bar,Decl(arrayLiteralContextualType.ts,14,36))
|
2014-10-18 01:53:18 +02:00
|
|
|
>[ new Giraffe(), new Elephant()] : (Giraffe | Elephant)[]
|
2014-10-10 23:41:14 +02:00
|
|
|
|
|
|
|
new Giraffe(),
|
|
|
|
>new Giraffe() : Giraffe
|
2015-04-13 22:54:22 +02:00
|
|
|
>Giraffe : typeof Giraffe, Symbol(Giraffe,Decl(arrayLiteralContextualType.ts,2,1))
|
2014-10-10 23:41:14 +02:00
|
|
|
|
|
|
|
new Elephant()
|
|
|
|
>new Elephant() : Elephant
|
2015-04-13 22:54:22 +02:00
|
|
|
>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()];
|
2015-04-13 22:54:22 +02:00
|
|
|
>arr : (Giraffe | Elephant)[], Symbol(arr,Decl(arrayLiteralContextualType.ts,26,3))
|
2014-10-18 01:53:18 +02:00
|
|
|
>[new Giraffe(), new Elephant()] : (Giraffe | Elephant)[]
|
2014-10-10 23:41:14 +02:00
|
|
|
>new Giraffe() : Giraffe
|
2015-04-13 22:54:22 +02:00
|
|
|
>Giraffe : typeof Giraffe, Symbol(Giraffe,Decl(arrayLiteralContextualType.ts,2,1))
|
2014-10-10 23:41:14 +02:00
|
|
|
>new Elephant() : Elephant
|
2015-04-13 22:54:22 +02:00
|
|
|
>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
|
2015-04-13 22:54:22 +02:00
|
|
|
>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
|
2015-04-13 22:54:22 +02:00
|
|
|
>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
|
|
|
|