Is there a way to declare an object in such a manner that it requires certain keys, while also allowing for the inclusion of any other keys?
Let's say we have an object called student
which must always include the keys name
and gender
, but can also have additional keys. How can this type be declared?
let student: { name: string, gender: string, ... };
//examples of valid assignments
student = {
name: 'Goku',
gender: 'male',
power: 'Super Saiyan'
}
student = {
name: 'Pikachu',
gender: 'unknown',
body: 'yellow',
shoeSize: 20
}
I've had trouble finding resources or tutorials on this specific topic. Is this considered bad practice, and if so, why?