wrong-type-report-generator
TypeScript icon, indicating that this package has built-in type declarations

0.0.15 • Public • Published

Motivation

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!

Installation

npm i wrong-type-report-generator

Usage

1. Generate wrong-type-report

import { generateWrongTypeReport } from 'wrong-type-report-generator';

const files = getFiles();

await generateWrongTypeReport({
    filePaths: files,
    outDirPath: './generated',
});

2. Use generated reporter with Axios then send wrong type report

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!
};

TODO

  • [ ] transform a.b.c -> a['b']['c'] (to support things like this -> asdf['asdf.asdf'])
  • [ ] Refactor spaghetti code
  • [ ] code generator tests
  • [ ] duplicated property error optimization
  • [ ] performance optimization

Dependencies (0)

    Dev Dependencies (10)

    Package Sidebar

    Install

    npm i wrong-type-report-generator

    Weekly Downloads

    3

    Version

    0.0.15

    License

    MIT

    Unpacked Size

    55 kB

    Total Files

    43

    Last publish

    Collaborators

    • changwoolab