DEV Community


Discussion on: Type-safe API mocking with Mock Service Worker and TypeScript

kettanaito profile image
Artem Zakharchenko Author

Thank you, Fakorede.

With the current implementation you'd have to use a union type to define such response:

interface TodoResponsePayload {
  todo: Todo

interface TodoResponseError {
  status: number
  message: string

type TodoResponse = TodoResponsePayload | TodoResponseError

rest.get<TodoId, TodoResponse>('/todo', handler).
Enter fullscreen mode Exit fullscreen mode
wati_fe profile image
Boluwatife Fakorede

Great. Thanks for your response