I have object of arrays, where each array is pair [value, function], where function accepts value in parameter:
const items = {
first: ['a', val => val.length], // val should be string
second: [[1, 2], val => val.push(3)] // val should be number[]
}
Is there any way to set the type of function parameter (second array item) the same as the type of first array item? I created this, but it's not working (a type of function parameter is always unknown):
type Items = {
[key: string]: any extends [infer Value, any] ? [Value, (val: Value) => any] : never
}
const items: Items = {
first: ['a', val => val.length], // val should be string, but is unknown
second: [[1, 2], val => val.push(3)] // val should by number[], but is unknown
}