As a newcomer to Angular and Typescript, I decided to watch some YouTube tutorials to better understand these technologies. I stumbled upon this particular tutorial which I followed along by copying the code.
Within the component I'm working on, I attempted to subscribe as shown in the video. However, I encountered an error message that reads:
Error: src/app/components/prof-btn/prof-btn.component.ts:34:43 - error TS2769: No overload matches this call. Overload 1 of 5, '(observer?: NextObserver | ErrorObserver | CompletionObserver | undefined): Subscription', gave the following error. Argument of type '(users: User[]) => Users[]' is not assignable to parameter of type 'NextObserver | ErrorObserver | CompletionObserver | undefined'. Property 'complete' is missing in type '(users: User[]) => Users[]' but required in type 'CompletionObserver'. Overload 2 of 5, '(next?: ((value: Object) => void) | undefined, error?: ((error: any) => void) | undefined, complete?: (() => void) | undefined): Subscription', gave the following error. Argument of type '(users: User[]) => Users[]' is not assignable to parameter of type '(value: Object) => void'. Types of parameters 'users' and 'value' are incompatible. The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? Type 'Object' is missing the following properties from type 'Users[]': length, pop, push, concat, and 26 more.
34 this.userService.getUsers().subscribe((users: User[]) => this.users = users);
node_modules/rxjs/internal/types.d.ts:64:5 64 complete: () => void; 'complete' is declared here.
ngOnInit() {this.userService.getUsers().subscribe((users: User[]) => this.users = users);}
userService
getUsers() {return this.webService.get('users');}
webService :
get(uri: string) {this.http.get(``${this.ROOT_URL}/${uri}``);}
In this scenario, I am subscribing to a service that is successfully returning data to me. Despite the program functioning correctly, I am still unsure about what the underlying issue might be.