haugan
haugan

Reputation: 405

Can I tell Typescript that both of a method's input parameters are of the same type?

In the following code:

foo(first: string, second: string) {
  // ..
}

Do I have to write string twice, or could I tell Typescript that; "hey, both of these parameters are of the same type".

Upvotes: 0

Views: 158

Answers (1)

k0pernikus
k0pernikus

Reputation: 66500

Yes, you have to declare the type of each parameter as the first and second parameter have nothing in common. You must declare their type explicitly.

Upvotes: 1

Related Questions