Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RemoteData example from Elm to use in TS
import ApiError from './ApiError';

interface NotFetched {
  kind: 'NotFetched'
}
interface IsFetching {
  kind: 'IsFetching'
}
interface Fetched<Data> {
  kind: 'Fetched',
  data: Data
}
interface ErrorFetching {
  kind: 'ErrorFetching',
  // ApiError returns an ErrorCode type of all error codes that your API could return e.g. 'RESOURCE_NOT_FOUND'
  error?: ApiError.ErrorCode
}
type RemoteData<Data> =
  | NotFetched
  | IsFetching
  | Fetched<Data>
  | ErrorFetching
  ;

export {
  NotFetched,
  IsFetching,
  Fetched,
  ErrorFetching,
  RemoteData,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment