34 lines
No EOL
1 KiB
Text
34 lines
No EOL
1 KiB
Text
==== tests/cases/compiler/arrayLiteralContextualType.ts (2 errors) ====
|
|
interface IAnimal {
|
|
name: string;
|
|
}
|
|
|
|
class Giraffe {
|
|
name = "Giraffe";
|
|
neckLength = "3m";
|
|
}
|
|
|
|
class Elephant {
|
|
name = "Elephant";
|
|
trunkDiameter = "20cm";
|
|
}
|
|
|
|
function foo(animals: IAnimal[]) { }
|
|
function bar(animals: { [n: number]: IAnimal }) { }
|
|
|
|
foo([
|
|
new Giraffe(),
|
|
new Elephant()
|
|
]); // Legal because of the contextual type IAnimal provided by the parameter
|
|
bar([
|
|
new Giraffe(),
|
|
new Elephant()
|
|
]); // Legal because of the contextual type IAnimal provided by the parameter
|
|
|
|
var arr = [new Giraffe(), new Elephant()];
|
|
foo(arr); // Error because of no contextual type
|
|
~~~~~~~~
|
|
!!! Supplied parameters do not match any signature of call target.
|
|
bar(arr); // Error because of no contextual type
|
|
~~~~~~~~
|
|
!!! Supplied parameters do not match any signature of call target. |