Lokomotywa
Lokomotywa

Reputation: 2844

Typed Array as Function Parameter not possible - why?

Why is this possible:

interface MyInterface{

    aggregate: (Array) => Array<string>;
}

But not this:

interface MyInterface{

    aggregate: (Array<string>) => Array<string>;
}

Upvotes: 1

Views: 48

Answers (2)

Herrington Darkholme
Herrington Darkholme

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

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

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

Related Questions