I have this class:
user.ts
const ADMIN = 1;
const AGENT = 2;
const ADJUSTER = 3;
const MANAGER = 4;
const MOTORCYCLIST = 5;
export class User {
id: number;
name: string;
email: string;
phone: string;
status: string;
role: number;
isAdmin(): boolean {
return this.role === ADMIN;
}
isAgent(): boolean {
return this.role === AGENT;
}
isAdjuster(): boolean {
return this.role === ADJUSTER;
}
isManager(): boolean {
return this.role === MANAGER;
}
isMotorcyclist(): boolean {
return this.role === MOTORCYCLIST;
}
}
For testing reasons I'm using a mock users array (for brevity I will show an array of just 5 users, but in my code I have more than 1000):
mock-users.ts
import { User } from '../models/user';
export const USERS: User[] = [{"id":301,"name":"Shirlee Zboncak","email":"[email protected]","phone":"044 93 1342 0977","status":"inactive","role":3},{"id":302,"name":"Erich Auer","email":"[email protected]","phone":"044 87 8444 6879","status":"inactive","role":2},{"id":303,"name":"Jerrold McDermott","email":"[email protected]","phone":"044 64 7490 1751","status":"inactive","role":3},{"id":304,"name":"Yael Hilpert","email":"[email protected]","phone":"044 16 9190 7970","status":"inactive","role":4},{"id":305,"name":"Pat Hodkiewicz","email":"[email protected]","phone":"044 12 0242 7692","status":"inactive","role":3}]
The problem is that that code fails with this message in console
And in my editor it shows this another message:
Missing property 'isAdmin' on type '{ "id": number; "name": string; "email": string; "phone": string; "status": string; "role": numbe...'.
How can I make my User class to not try to assign the methods. I only want to assign those id, name, email, phone, status and role properties. I have tried to use a constructor but the error is the same.