Issue
I am trying to declare following variable in angular 12
private subject = new BehaviorSubject<ApiResponse>({});
I get error
Argument of type '{}' is not assignable to parameter of type 'ApiResponse'
Type '{}' is missing the following properties from type 'ApiResponse'
The class ApiResponse has following properties
export interface ApiResponse {
success: boolean
message: string
exception: any
totalRowCount: number
}
If I declare each property explicitly, it works without error Is there a way to declare an empty object without declaring each property explicitly ?
Solution
Use ?
for optional properties
export interface ApiResponse {
success?: boolean;
message?: string;
exception?: any;
totalRowCount?: number;
}
Answered By - Vishnudev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.