Created
July 17, 2023 06:51
-
-
Save turbod/8158457fb5e0156c81a9ca2ffa9b8e4f to your computer and use it in GitHub Desktop.
Api response different types based on status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ApiResponse<T> = | |
| { status: 'success'; data: T; timestamp: Date } | |
| { status: 'error'; message: string; timestamp: Date } | |
const response1: ApiResponse<number> = { | |
status: 'success', | |
data: 100, | |
timestamp: new Date(), | |
} | |
const response2: ApiResponse<number> = { | |
status: 'success', | |
message: 'Something went wrong', | |
timestamp: new Date(), | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment