ReactiveX/rxjs · error · TypeError

Invalid notification, missing "kind"

Error message

Invalid notification, missing "kind"

What it means

observeNotification dispatches a notification to an observer based on its kind field. If notification.kind is not a string (missing, undefined, number), the notification is malformed and a TypeError is thrown before any observer method is called.

Source

Thrown at packages/rxjs/src/notification.ts:105

  static createComplete<T = never>(): Notification<T> & CompleteNotification {
    return Notification.completeNotification as unknown as Notification<T> & CompleteNotification;
  }
}

export const COMPLETE_NOTIFICATION: CompleteNotification = Object.freeze({ kind: 'C' });

export function nextNotification<T>(value: T): NextNotification<T> {
  return { kind: 'N', value };
}

export function errorNotification(error: any): ErrorNotification {
  return { kind: 'E', error };
}

export function observeNotification<T>(notification: ObservableNotification<T>, observer: Partial<Observer<T>>): void {
  if (typeof (notification as { kind?: unknown }).kind !== 'string') {
    throw new TypeError('Invalid notification, missing "kind"');
  }

  if (notification.kind === 'N') {
    observer.next?.(notification.value);
  } else if (notification.kind === 'E') {
    observer.error?.(notification.error);
  } else {
    observer.complete?.();
  }
}

View on GitHub (pinned to 54796b38a5)

Solutions

  1. Validate kind is one of 'N'/'E'/'C' (a string) before calling observeNotification/observe
  2. Reconstruct notifications with nextNotification/errorNotification/completeNotification
  3. Fix the producer that dropped the kind field (check destructuring/serialization)

Example fix

// before
obs[observe]({ value: 1 }); // missing kind -> throws
// after
obs[observe]({ kind: 'N', value: 1 });
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof (notification as any)?.kind !== 'string') throw new TypeError('notification missing kind');
observeNotification(notification, observer);

Type guard

const hasStringKind = (n: unknown): n is ObservableNotification<any> =>
  typeof (n as { kind?: unknown })?.kind === 'string';

Prevention

When it happens

Trigger: observeNotification({}, observer), observeNotification(null?.valueOf(), observer) via the observe operator, or a materialize/serialize round-trip that dropped the kind field.

Common situations: Feeding arbitrary objects into the observe operator, or bugs in custom notification producers (e.g. renaming kind during transport or destructuring without the kind property).

Related errors


AI-assisted analysis of ReactiveX/rxjs@54796b38a5 (2026-08-28). Data as JSON: /api/errors/015b95dc439e33cd. Report an issue: GitHub.