Skip to content
Advertisement

How to assign types for the elements in an object

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).

Advertisement

Answer

interfate userType {
    username: string,
    email: string
}

interface initialStateInterface {
  user: userType;
  age: number;
}
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement