json-typings
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

json-typings

Generate TypeScript type definitions from JSON-compatible JavaScript objects

Do you want to get type declarations for JSON-like JavaScript objects at runtime? Do you NOT want to ship 8MB of TypeScript as a dependency to do so? Then this might be what you are looking for!

Usage

TL;DR: take a JSON-like value and pass it into getDeclaration, get back its typings.

const { getDeclaration } = require('json-typings')
 
const person = {
    firstname: 'John',
    lastname: 'Doe',
    luckyNumber: 42,
    awesome: true,
    children: [
        'Jane',
        'Max'
    ]
}
 
console.log(getDeclaration(person));

outputs (without linebreaks and spaces)

{
    firstname: string;
    lastname: string;
    luckyNumber: number;
    awesome: bolean;
    chlidren: string[];
}

The above output can be used to describe this object as a TypeScript declaration. You can add it to a .d.ts file like this:

declare const person = { firstname: string/* ... */ };

API

const { getDeclaration } = require('json-typings')

Install

With npm installed, run

$ npm install json-typings

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.2
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.2
    1
  • 0.0.1
    0

Package Sidebar

Install

npm i json-typings

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

6.99 kB

Total Files

6

Last publish

Collaborators

  • pedily