Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rx-stateful: stricter typing per context #88

Open
mikelgo opened this issue Sep 18, 2023 · 0 comments
Open

Rx-stateful: stricter typing per context #88

mikelgo opened this issue Sep 18, 2023 · 0 comments

Comments

@mikelgo
Copy link
Owner

mikelgo commented Sep 18, 2023

This will improve type narrowing, especially in templates.

RxStatefulWithValue/Error/Suspense

type Context = 'suspense' | 'error' | 'next';

interface Stateful<T, E> {
  value: T | null;
  hasValue: boolean;
  error: E | undefined;
  hasError: boolean;
  context: Context;
  isSuspense: boolean;
}

interface StatefulWithSuspense<T> {
  value: T | null;
  hasValue: boolean;
  hasError: false;
  error: undefined;
  // suspense
  context: 'suspense';
  // true
  isSuspense: true;
}

interface StatefulWithValue<T> {
  value: T;
  // true
  hasValue: true;
  //false
  hasError: false;
  error: undefined;
  // next
  context: 'next';
  // false
  isSuspense: false;
}
interface StatefulWithError<T, E> {
  value: null;
  // true
  hasValue: false;
  //false
  hasError: true;
  error: E;
  // next
  context: 'error';
  // false
  isSuspense: false;
}

type TODO<T, E> =
  | StatefulWithSuspense<T>
  | StatefulWithValue<T>
  | StatefulWithError<T, E>;

https://stackblitz.com/edit/typescript-mjrqck?file=index.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant