Answer the question
In order to leave comments, you need to log in
What should an object look like when the types intersect?
Hello.
There are custom types, one of them uses type intersection:
export type UserInfoType = {
name: string,
login: string,
age: number | string,
gender: string
};
export type UserType = {
[key: string]: UserInfoType;
} & {
city: string;
country: string;
};
const users: UserType = {
"Anna": {
name: "Anna",
login: "Ann_90",
age: 28,
gender: female
},
"Tony": {
name: "Tony",
login: "ttt_comeback",
age: 25,
gender: male
},
"Lanessa": {
name: "Lanessa",
login: "Lana_142",
age: 35,
gender: female
},
city: Tampa,
country: USA,
}
Answer the question
In order to leave comments, you need to log in
Something tells me this might work.
type UsersValues = {
[key: string]: string | number;
};
type UserType = {
[key: string]: UsersValues | string;
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question