I'm toying around with Rxjs and was trying to see how subscriptions worked. This is my code:
export class AppComponent implements OnInit {
title = 'hello_world_project';
ngOnInit() {
const rickRoll = new Observable((observable) => {
observable.next('Never gonna give you up');
observable.next('Never gonna let you down');
});
rickRoll.subscribe(this.uselessWrapperFunc);
console.log('Rxjs is fun');
}
uselessWrapperFunc(message: String): void {
console.log(message);
}
}
And it gave me the error saying "Argument of type 'unknown' is not assignable to parameter of type 'String'"
However, if I try doing rickRoll.subscribe(console.log), it worked as expected. So in this case, why has console.log seemingly been called with the value from the observable, while the uselessWrapperFunc seems to have been passed in the entire observable itself?
Thanks! Any insight will be appreciated
Update: Would specifying the type of the observable help?