ave ave - 10 months ago 40
TypeScript Question

Is it possible to return a tuple of two numbers?

When I declare a function as

const coordinates = (id: number): ([number, number]) => {

the error I get is
[ts] Duplicate identifier 'number'.

If I omit type signature for return value, then it infers it as

Answer Source
const coordinates = (id: number): [number, number] => [id, id];

No need for the parenthesis around the return tuple type

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download