let adminList = origData.map((data) => { return data as adminPermission.AdminUser })
export interface AdminUser {
uid: string
displayName: string
email: string
emailVerified: boolean
isAnonymous: boolean
photoURL: string
}
I want to reformat my data same with the structure of 'AdminUser' interface. But after typecase " ~ as ~ ", the result is exactly the same as before.
So, I just had to make a longer code.
- Casting doesn't work, so I changed the way to define a class.
let adminList = origData.map((data) => {
let newData = new adminPermission.AdminUser(data)
return newData
})
- Defined new Class
export class AdminUser {
constructor(object: any) {
this.uid = object.uid
this.displayName = object.displayName
this.email = object.email
this.emailVerified = object.emailVerified
this.isAnonymous = object.isAnonymous
this.photoURL = object.photoURL
}
}
It works, but it is not what I expected in Typescript usage. And totally useless and messy code.
How can I reselect object member using an Interface?