In my current Angular project, I am using RXJS and Typescript. The code snippet below shows what I have implemented:
const sub = new Subject<never>();
My understanding is that the above line implies that any subscriber defining the 'next' and 'error' methods (as shown in the code below) will never trigger the 'next' method. Instead, only the 'error' method will be invoked, if necessary.
sub.subscribe(() => /*perform action with 'next' value*/, error => /*perform action with 'error' value*/)
However, despite my assumptions, when I execute the following code:
sub.next();
No compilation errors are thrown.
Based on my understanding, the generic specified for the Subject defines the type returned by the subject, so 'never' should prevent the invocation of the next method.
Could someone shed some light on why this behavior is occurring? Is it a bug, a deliberate feature, or simply a misunderstanding on my part?