Do you see any issues with the object being an instance of ChatRoom
? Let me know your thoughts.
Class:
export class ChatRoom {
public id?: number;
public name_of_chat_room: string;
public chat_creator_user_id: number;
public chat_room_is_active: 0 | 1;
public chat_room_is_shareable: 0 | 1;
public time_of_most_recent_message?: Date | string;
public created_at?: Date | string;
constructor(chatRoom: {
name_of_chat_room: string;
chat_creator_user_id: number;
chat_room_is_active: 0 | 1;
chat_room_is_shareable: 0 | 1;
time_of_most_recent_message?: Date | string;
}) {
Object.assign(this, chatRoom);
}
}
finalResult
object that is not working as expected:
{
name_of_chat_room: 'First Posted Chat Room',
chat_creator_user_id: 21,
chat_room_is_active: 1,
chat_room_is_shareable: 1
}
if
statement that needs attention:
if (finalResult instanceof ChatRoom){
console.log("hooray")
}else{
console.log("foooey")
}
Complete code snippet
export class ChatRoom {
public id ? : number;
public name_of_chat_room: string;
public chat_creator_user_id: number;
public chat_room_is_active: 0 | 1;
public chat_room_is_shareable: 0 | 1;
public time_of_most_recent_message ? : Date | string;
public created_at ? : Date | string;
constructor(chatRoom: {
name_of_chat_room: string;
chat_creator_user_id: number;
chat_room_is_active: 0 | 1;
chat_room_is_shareable: 0 | 1;
time_of_most_recent_message ? : Date | string;
}) {
Object.assign(this, chatRoom);
}
}
let finalResult = {
name_of_chat_room: 'First Posted Chat Room',
chat_creator_user_id: 21,
chat_room_is_active: 1,
chat_room_is_shareable: 1
}
if (finalResult instanceof ChatRoom) {
console.log("hooray")
} else {
console.log("foooey")
}