Ensuring that the structure of the http JSON response aligns with a typescript interface/type is crucial for our javascript integration tests against the backend.
Take, for example, our CurrentUser interface:
export interface CurrentUser {
id: number;
firstname: string;
lastname: string;
roles: string[];
}
If a returned object from the backend doesn't include a firstname
property but includes an age
property, it's essential to detect this mismatch and fail the test at runtime.
We aim to automate these checks without manually coding assertions for each field. However, given that typescript interfaces don't exist at runtime, how can we leverage typescript for such validations?
If achieving this through typescript is unfeasible, are there any alternative libraries or patterns we could explore?