f.khantsis
f.khantsis

Reputation: 3560

discrete names for tuple method parameters

I have to define a method, that by restriction can only be called with one parameter (a Subscriber). I need to pass several values, so I group them in a tuple.

In the subscriber, I would like to access each variable of the tuple as its own name. So I am looking for syntax like

([name:string, age:number, salary: number]) => {
  console.log("our name is " + name);
}

Does typescript support this?

Upvotes: 1

Views: 49

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 250156

You can use array de-structuring syntax:

([name, age, salary]: [string, number, number]) => {
    console.log("our name is " + name);
}

Upvotes: 1

Related Questions