json2ts icon indicating copy to clipboard operation
json2ts copied to clipboard

Convert method is crashed with an empty array

Open lomonosv opened this issue 1 year ago • 0 comments

Hey! Please, review this issue. Convert method of Json2Ts instance is crashed with an empty array as argument.

import { Json2Ts } from 'json2ts/src/json2ts';

const json = [];
const tsString = new Json2Ts().convert(JSON.stringify(json));

As the result application is failed with an error:

TypeError: Cannot read properties of undefined (reading 'replace')
    at Json2Ts.formatCharsToTypeScript

In my opinion it should return interface like this - export interface RootObject {}. Can we review this issue as a bug and fix inside the library or it should be handled outside?

lomonosv avatar May 24 '23 12:05 lomonosv