Complete the code to define a type for the API response.
type ApiResponse = {
data: string[];
status: [1];
};The status field is a number representing HTTP status codes.
Complete the function signature to specify the return type as a Promise of ApiResponse.
function fetchData(): [1] { return fetch('/api/data').then(res => res.json()); }
The function returns a Promise that resolves to ApiResponse.
Fix the error in the type assertion to ensure the response is treated as ApiResponse.
const response = await fetch('/api/data'); const data = (await response.json()) as [1];
Use ApiResponse to safely assert the JSON matches the expected type.
Fill both blanks to create a type guard function that checks if an object is ApiResponse.
function isApiResponse(obj: any): obj is [1] { return obj && typeof obj.status === [2]; }
The type guard returns true if obj has a status property of type number.
Fill all three blanks to filter valid ApiResponse objects from an array.
const responses: any[] = [...]; const validResponses = responses.filter((item): item is [1] => { return item && typeof item.status === [2] && Array.isArray(item.[3]); });
This filter keeps only objects that match ApiResponse by checking status is a number and data is an array.