Reputation: 2844
Why is this possible:
interface MyInterface{
aggregate: (Array) => Array<string>;
}
But not this:
interface MyInterface{
aggregate: (Array<string>) => Array<string>;
}
Upvotes: 1
Views: 48
Reputation: 6315
Please read the handbook.
TypeScript don't support writing function parameter type alone, you have to provide its parameter name.
interface MyInterface{
aggregate: (args: Array<string>) => Array<string>;
}
Upvotes: 3
Reputation: 249506
Because the first one does not do what it appears to do. Your intention was probably to define a function with a parameter of type Array
. While in actuality you defined a function with a parameter named Array
of type any
If you don't specify parameter types they are assumed to be any
. You can be warned about this if you specify the noImplicitAny
flag.
Upvotes: 3