1

Why is this possible:

interface MyInterface{

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

But not this:

interface MyInterface{

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

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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>;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.