Can someone please help me figure out what I'm doing wrong? I'm attempting to implement an interface inside a class and initialize it, but I keep encountering this error:
Uncaught TypeError: Cannot set property 'name' of undefined
at new User (eval at setTimeout (main.js:493), <anonymous>:4:24)
at eval (eval at setTimeout (main.js:493), <anonymous>:9:14)
at setTimeout (main.js:493)
Here is my attempted code:
interface UserInterface {
name: string
email: string
}
class User {
id: string
data: UserInterface
constructor(){
this.data.name = ''
this.data.name = ''
this.id = ''
}
}
const user = new User()
console.log(user.data)
Thanks in advance for any assistance!