Struggling to implement a login feature in Angular, encountering an error related to promises: "Type 'Promise<ApiResponse<UserLogged> | undefined>' is not assignable to type 'Promise<ApiResponse<UserLogged>>'. ts2322
login(user?:string, password?:string):Promise<ApiResponse<User>> {
return new Promise((resolve) => {
let promise:Promise<ApiResponse<UserLogged>>;
if (user && password) //logging in
promise=this.http.post<ApiResponse<UserLogged>>(this.baseUrl + "login", {user: user, password: password}).toPromise();
else //checking for active session on the server
promise=this.http.get<ApiResponse<UserLogged>>(this.baseUrl + "login").toPromise();
//process response
});
}
apiresponse.ts
export interface ApiResponse<T> extends BaseDTO{
status: number;
message?: string;
data?: T
}
baseDTO
export interface BaseDTO {
}
Seeking clarification on my mistake.
Apologies for my poor English.
Thank you.
User
export interface User extends BaseIdDTO{
user:string;
password?:string;
mail:string;
name?:string
Resolved the issue by changing the tsconfig.json from "strict:true" to "strict:false". Error disappeared.