I create a UserAuth
interface
:
user-auth.module.ts
export interface UserAuth {
id: string;
name: string;
email: string;
created_at?: string;
updated_at?: string;
}
, I declare an authUser
object of this interface
in chat.component.ts:
authUser = JSON.parse(localStorage.getItem('user') || '{}').value.authUser;
I receive this authUser object in list.component.ts :
@Input() authUser !: UserAuth;
I want to declare an object of this UserAuth
interface
list.component.ts:
changeToGroupChat() {
const user : UserAuth = null;
this.selectedAuthUser.emit(user);
}
but it gives me error:
error TS2322: Type 'null' is not assignable to type 'UserAuth'
CodePudding user response:
Try to use union type of typescript:
const user : UserAuth | null = null;