export class User {
private readonly props: UserProps;
constructor(props: UserProps) {
this.props = userSchema.parse(props);
for (const key of Object.keys(props) as Array<keyof UserProps>) {
Object.defineProperty(this, key, {
get: () => this.props[key],
enumerable: true,
});
}
}
}
const user = new User({firstname: 'John', /* other fields */});
console.log(user.firstname); // TS2339: Property firstname does not exist on type User