interface Individual {
name: string,
age: number,
height: number,
}
const alice: Individual = {
name: 'alice',
age: 30,
height: 160
}
// Is there a way to specify the type of the second parameter (details) without resorting to 'any'?
const updateIndividual: (person: Individual, details: any) => void = (person, details) => {
Object.assign(person, details)
}
updateIndividual(alice, {height: 165})
console.log(alice) // { name: 'alice', age: 30, height: 165 }
updateIndividual(alice, {age: 31})
console.log(alice) // { name: 'alice', age: 31, height: 165 }
You can observe that the second parameter 'info' might include certain attributes of the Individual type, so how can I specify its type?
I initially considered using the type assertion "info as Individual," but it might not be the optimal solution and could lead to issues.