I am working with RXJS and Typescript in an angular project. I have written the following in my code:
const sub = new Subject<never>();
I expect this line to mean that any subscriber that defines the 'next' and 'error' methods, as can be seen below, will never have the 'next' method called. Only the 'error' method will be called, if at all.
sub.subscribe(() => /*do something with 'next' value*/, error => /*do something with 'error' value*/)
However, when I write the following:
sub.next();
I do not get a compilation error.
From my understanding the Subject generic is the type returned by the subject, so never means that we never call the next method.
Can anyone explain why? Is this a bug, a feature or misunderstanding on my part?