=== tests/cases/compiler/arrayLiteralContextualType.ts === interface IAnimal { >IAnimal : IAnimal name: string; >name : string } class Giraffe { >Giraffe : Giraffe name = "Giraffe"; >name : string >"Giraffe" : string neckLength = "3m"; >neckLength : string >"3m" : string } class Elephant { >Elephant : Elephant name = "Elephant"; >name : string >"Elephant" : string trunkDiameter = "20cm"; >trunkDiameter : string >"20cm" : string } function foo(animals: IAnimal[]) { } >foo : (animals: IAnimal[]) => void >animals : IAnimal[] >IAnimal : IAnimal function bar(animals: { [n: number]: IAnimal }) { } >bar : (animals: { [n: number]: IAnimal; }) => void >animals : { [n: number]: IAnimal; } >n : number >IAnimal : IAnimal foo([ >foo([ new Giraffe(), new Elephant()]) : void >foo : (animals: IAnimal[]) => void >[ new Giraffe(), new Elephant()] : (Giraffe | Elephant)[] new Giraffe(), >new Giraffe() : Giraffe >Giraffe : typeof Giraffe new Elephant() >new Elephant() : Elephant >Elephant : typeof Elephant ]); // Legal because of the contextual type IAnimal provided by the parameter bar([ >bar([ new Giraffe(), new Elephant()]) : void >bar : (animals: { [n: number]: IAnimal; }) => void >[ new Giraffe(), new Elephant()] : (Giraffe | Elephant)[] new Giraffe(), >new Giraffe() : Giraffe >Giraffe : typeof Giraffe new Elephant() >new Elephant() : Elephant >Elephant : typeof Elephant ]); // Legal because of the contextual type IAnimal provided by the parameter var arr = [new Giraffe(), new Elephant()]; >arr : (Giraffe | Elephant)[] >[new Giraffe(), new Elephant()] : (Giraffe | Elephant)[] >new Giraffe() : Giraffe >Giraffe : typeof Giraffe >new Elephant() : Elephant >Elephant : typeof Elephant foo(arr); // ok because arr is Array not {}[] >foo(arr) : void >foo : (animals: IAnimal[]) => void >arr : (Giraffe | Elephant)[] bar(arr); // ok because arr is Array not {}[] >bar(arr) : void >bar : (animals: { [n: number]: IAnimal; }) => void >arr : (Giraffe | Elephant)[]