When your DTO is different from your backend's specification and have no way to detect it, it is hard to debug the error!
Below is an example of WTF moment.
// Your DTO
interface meDto {
...
user: {
id: number;
}
...
}
// From your backend
{
...
user: "{id: 123}" // WTF?! it is too hard to find!
...
}
So, when Backend's API response is different from our DTO, report it!
npm i wrong-type-report-generator
import { generateWrongTypeReport } from 'wrong-type-report-generator';
const files = getFiles();
await generateWrongTypeReport({
filePaths: files,
outDirPath: './generated',
});
import { generateReporter } from 'wrong-type-report-generator';
import { validateDto } from './generated';
const report = generateReporter((errorReport) => {
sendForDebug(errorReport);
});
export const xxxApi = async () => {
return axios.get('www.xxx.xxx').then(report(validateDto)); // use generated reporter here!
};
- Generation Optimization
- Refactor spaghetti code
- performance optimization
- code generator tests
- duplicated property error optimization