API Response Handler with Generic Types
MediumType an API response handler for Hack Frontend. The function should accept a URL and return a Promise with typed data.
Requirements:
- Generic function fetchHackFrontendAPI<T>
- Returns Promise<ApiResponse<T>>
- ApiResponse has success, data or error
- Types should narrow correctly via type guards
TypeScript•UTF-8
Run your code to see results.
Click the Run button above
API Response Handler with Generic Types
MediumType an API response handler for Hack Frontend. The function should accept a URL and return a Promise with typed data.
Requirements:
- Generic function fetchHackFrontendAPI<T>
- Returns Promise<ApiResponse<T>>
- ApiResponse has success, data or error
- Types should narrow correctly via type guards
Examples:
Input 1: fetchHackFrontendAPI<User>("/api/user")
Output 1: Promise<ApiResponse<User>>
Output
Run your code to see results.