1.3.2 • Published 3 years ago
typesgenerator v1.3.2
Typesgenerator
Typesgenerator helps in creating typescript types/interfaces from JSON or JavaScript-object.
Installation and Usage
As Package: To use a function for printing type:
npm i -D typesgeneratorBelow is usage example for printing the type from the javascript/json object:
import { printType } from 'typesgenerator';
const object = {
name: 'john doe',
hobbies: [
{ name: 'coding', outdoor: false },
{ name: 'cycling', outdoor: true },
],
age: 35,
score: [0, 'A', ['1st']],
};
printType(object, 'Person');
//console output:
/*
export type PersonHobbie = {
name: string;
outdoor: boolean;
};
export type Person = {
name: string;
hobbies: PersonHobbie[];
age: number;
score: (number | string | string[])[];
};
*/As CLI: To create a typescript file from JSON:
npm i -g typesgeneratorBelow is the usage example that will create a new file containing types:
tg -n <Type name> -s <path-to-json> -t <path-to-target-directory>Below are the suppored arguments:
-nor-Nor--type-name: Name to be given to type-sor-Sor--source-path: path to the json- (optional )
-tor-Tor--target-path: path to the type-file to be generated
GitHub: https://github.com/emreSlim/typescript-types-generator
Issues: https://github.com/emreSlim/typescript-types-generator/issues