Home > Software engineering >  Why do array type become tuples?
Why do array type become tuples?

Time:03-04

I have a problem with typescript

function watches<T extends unknown[]>(
  sources: [...T],
  cb: (value: T) => any,
){

}

watches([{a:1},'1'],(b)=>{})  // b -> [{a: number}, string]

this is exactly what i want, but why?

why (value: T) => any value is a tuple?

i feel it incredible.

CodePudding user response:

I think I understand your question.

(value: T) => any this isn't a tuple.

This is an anonymous function.

The parentheses in the type are not the same as the parentheses around a tuple.

This would be like defining a function...

function myFunction(value: T) => any

The type of this function is...

(value: T) => any
  • Related