Home > Back-end >  How to assign types for the elements in an object
How to assign types for the elements in an object

Time:12-12

interface initialStateInterface {
  user: object;
  age: number;
}

const initialState = {
  user: { username: "", email: "" },
  age: 0,
};

Here I have the interface type assigned to the user which is an object. Is there any way to assign the types to it's elements?

What I'm trying to do,

user: (username: string,email: string).

CodePudding user response:

interfate userType {
    username: string,
    email: string
}

interface initialStateInterface {
  user: userType;
  age: number;
}
  • Related