fix(frontend): ApiResponse data nullability contract

- Change ApiResponse.data from T to T | null to match backend reality
- Add compile-time type contract file (http.typecheck.ts)
- Maintain backward compatibility with existing service calls
- Add test for success response with null data

Refs: review-fix-closure-2026-05-28 ApiResponse nullability
This commit is contained in:
Your Name
2026-05-29 12:32:09 +08:00
parent f758297a6e
commit 320aa9476f
4 changed files with 26 additions and 3 deletions

View File

@@ -566,6 +566,22 @@ describe('http client', () => {
})
})
it('returns null when a successful response carries null data', async () => {
const fetchMock = vi.mocked(fetch)
fetchMock.mockResolvedValueOnce(
jsonResponse({
code: 0,
message: 'ok',
data: null,
}),
)
const { get } = await loadModules()
const result = await get<null>('/nullable-success', undefined, { auth: false })
expect(result).toBeNull()
})
it('converts aborted requests into timeout AppErrors', async () => {
vi.useFakeTimers()
const fetchMock = vi.mocked(fetch)