Imagine I have an interface:
interface Cat {
name: string;
age: number;
color: string;
}
Now, I want to create an object with a new interface that extends partial Cat and adds new properties:
interface MyCat extends Partial<Cat> {
sex: "male" | "female"
}
const cat: MyCat = {name: "Tom", sex: "male"}
Currently, this is working fine. However, what if I don't want to declare a new interface (MyCat) if I won't use it again, and instead just want to assign the type when creating the object like this:
const cat: Partial<Cat> {sex: "male" | "female"} = {name: "Tom", sex: "male"}
How can I achieve this?