npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

auto-typegen

v1.0.4

Published

Automatically generate TypeScript interfaces from JSON data, API responses, or database schemas. Perfect for Mongoose, Sequelize, and raw data. Simplify your workflow and ensure type safety with just one function call!

Readme

auto-typegen 🚀

npm version License Downloads

Automatically generate TypeScript interfaces from JSON data, API responses, or database schemas. Perfect for Mongoose, Sequelize, and raw data. Simplify your workflow and ensure type safety with just one function call!


Features ✨

  • Instant Type Generation: Convert JSON/API responses to TypeScript interfaces in one call.
  • ORM Support: Works seamlessly with Mongoose and Sequelize.
  • Universal: Runs in Node.js (writes files) and browsers (triggers downloads).
  • Zero Config: Simple API with smart defaults.
  • Nested Objects: Handles complex data structures effortlessly.

Installation 💻

npm install auto-typegen
# or
yarn add auto-typegen

Usage 🚀

1. In React ⚛️

import { createTypedFetch } from 'auto-typegen';

const fetchTodo = async () => {
  const res = await fetch('https://api.example.com/todos/1');
  const todo = await res.json();

  await createTypedFetch({
    interfaceName: 'Todo',
    data: todo,
    outputPath: 'TodoType.ts',
  });
};

Browser Behavior: Triggers a download of TodoType.ts with:

interface Todo {
  userId: number;
  id: number;
  title: string;
  completed: boolean;
}

export { Todo };

2. Basic Example (Node.js)

import { createTypedFetch } from 'auto-typegen';

const user = {
  id: 1,
  name: 'Alice',
  email: '[email protected]',
  roles: ['admin', 'user'],
};

createTypedFetch({
  interfaceName: 'User',
  data: user,
  outputPath: './types/user-types.ts',
});

Generated File (user-types.ts):

interface User {
  id: number;
  name: string;
  email: string;
  roles: string[];
}

export { User };

3. With Mongoose 🍃

import { createTypedFetch } from 'auto-typegen';
import UserModel from './models/User';

const user = await UserModel.findOne({ email: '[email protected]' });

createTypedFetch({
  interfaceName: 'User',
  data: user,
  outputPath: './types/mongoose-user.ts',
});

Output:

interface User {
  _id: string;
  email: string;
  createdAt: Date;
  updatedAt: Date;
  __v: number;
}

export { User };

4. With Sequelize 🗄️

import { createTypedFetch } from 'auto-typegen';
import Product from './models/Product';

const product = await Product.findByPk(123);

createTypedFetch({
  interfaceName: 'Product',
  data: product,
  outputPath: './types/sequelize-product.ts',
});

Output:

interface Product {
  id: number;
  name: string;
  price: number;
  createdAt: Date;
  updatedAt: Date;
}

export { Product };

5. With Raw SQL Data 🐬

import { createTypedFetch } from 'auto-typegen';
import { executeQuery } from './database';

const results = await executeQuery('SELECT * FROM orders WHERE user_id = 456');

createTypedFetch({
  interfaceName: 'Order',
  data: results[0],
  outputPath: './types/sql-order.ts',
});

Output:

interface Order {
  id: number;
  user_id: number;
  total: number;
  created_at: Date;
}

export { Order };

API 📚

createTypedFetch(options)

Generates and saves TypeScript interfaces.

Options

| Parameter | Type | Required | Description | | --------------- | -------- | -------- | ------------------------------------------------------ | | interfaceName | string | Yes | Name for the root interface (e.g., "User") | | data | any | Yes | Data object to analyze | | outputPath | string | Yes | File path to save interfaces (e.g., "./types/user.ts") |

FAQ ❓

Q: How do I handle circular references? A: The library automatically detects and handles circular references by using any for the offending fields.

Q: Can I customize date handling? A: Dates are always typed as Date. For custom formatting, transform your data first.

Q: Does it work with Next.js/Nuxt.js? A: Yes! Works in any Node.js or browser environment.

Contributing 🤝

Found a bug? Want a feature?

  1. Fork the repo → git clone your-fork-url
  2. Create a branch → git checkout -b cool-feature
  3. Commit changes → git commit -m "Add cool feature"
  4. Push → git push origin cool-feature
  5. Open a PR!

GitHub Repository

License 📜

MIT © GAZI ASSADUJJAMAN MAMUN

⭐ Star this repo if you love type-safe coding! 🚀