typeweaver
v1.1.3
Published
Stop manually syncing types between your backend and frontend. Auto-generate TypeScript types from your ORM schemas.
Maintainers
Readme
🧵 TypeWeaver
Stop manually syncing types between your backend and frontend.
Auto-generate TypeScript interfaces from your ORM schemas in real-time.
🔥 The Problem
Full-stack TypeScript developers face a daily problem:
// Backend: Update User model
const userSchema = new Schema({
name: String,
email: String,
phoneNumber: String, // ← NEW FIELD
});
// Frontend: Types are now OUT OF SYNC ❌
interface User {
name: string;
email: string;
// Missing phoneNumber!
}
// Result: Runtime bugs that TypeScript should have caughtThe consequences:
- ⏰ 30+ minutes per week manually copying types
- 🐛 Type mismatches cause production bugs
- 🔄 Constant context switching between backend/frontend
- 😤 Forgotten updates slip through code reviews
✨ The Solution
# One-time setup
npx typeweaver init
# Generate types once
npx typeweaver generate
# Or watch mode (auto-sync on every change)
npx typeweaver watchThat's it. Your frontend types stay in sync automatically.
🚀 Quick Start
Run locally (Windows PowerShell)
If you're on Windows and using PowerShell, here are copy/paste-friendly commands:
# install deps
npm install
# interactive setup
npx typeweaver init
# generate types once
npx typeweaver generate
# watch mode
npx typeweaver watch
# run tests
npm test
# run dev CLI
npm run devInstallation
npm install -D typeweaverSetup (Interactive)
npx typeweaver initThis creates typeweaver.config.json:
{
"orm": "prisma",
"schemaPath": "./prisma/schema.prisma",
"outputPath": "./types",
"outputMode": "single"
}Generate Types
# One-time generation
npx typeweaver generate
# Watch mode (auto-regenerate on changes)
npx typeweaver watch📋 Features
✅ Supported ORMs
| ORM | Status | Description | | ------------- | -------------- | ------------------------- | | Prisma | ✅ Ready | Parse schema.prisma files | | Mongoose | ✅ Ready | Parse Schema definitions | | TypeORM | 🚧 Coming Soon | Parse decorators | | Sequelize | 🚧 Coming Soon | Parse models |
✨ Key Features
- Zero Migration - Works with your existing code
- Real-Time Sync - Watch mode updates types instantly (<500ms)
- Safe Writes - Automatic backups before overwriting
- Multi-ORM - Prisma, Mongoose, and more
- Flexible Output - Single file or one file per model
- Type-Safe - Handles complex types, enums, arrays, references
- Smart Detection - Auto-detects your ORM
📖 Usage Examples
Prisma
// schema.prisma
model User {
id String @id @default(cuid())
email String @unique
name String
age Int?
posts Post[]
}
model Post {
id String @id
title String
content String?
author User @relation(fields: [authorId], references: [id])
authorId String
}Generated TypeScript:
// types/index.ts
export interface User {
id: string;
email: string;
name: string;
age?: number | null;
posts: string[];
}
export interface Post {
id: string;
title: string;
content?: string | null;
author: string;
authorId: string;
}Mongoose
// models/User.js
const userSchema = new Schema({
name: { type: String, required: true },
email: { type: String, required: true },
age: Number,
role: { type: String, enum: ["user", "admin"] },
posts: [{ type: Schema.Types.ObjectId, ref: "Post" }],
});Generated TypeScript:
// types/index.ts
export interface User {
name: string;
email: string;
age?: number | null;
role: "user" | "admin";
posts: string[];
}⚙️ Configuration
Config File (typeweaver.config.json)
{
"orm": "auto",
"modelsPath": "./models",
"schemaPath": "./prisma/schema.prisma",
"outputPath": "./types",
"outputMode": "single",
"watch": false,
"includeComments": true,
"exclude": ["**/node_modules/**", "**/*.test.{js,ts}"]
}Configuration Options
| Option | Type | Default | Description |
| ----------------- | -------- | -------------------------- | ---------------------------------------- |
| orm | string | "auto" | ORM to use: auto, prisma, mongoose |
| modelsPath | string | "./models" | Path to Mongoose models |
| schemaPath | string | "./prisma/schema.prisma" | Path to Prisma schema |
| outputPath | string | "./types" | Where to generate types |
| outputMode | string | "single" | single file or separate files |
| watch | boolean | false | Enable watch mode |
| includeComments | boolean | true | Include JSDoc comments |
| readonly | boolean | false | Generate readonly properties |
| exclude | string[] | [] | Files to exclude |
🖥️ CLI Commands
init
Initialize configuration with interactive prompts.
npx typeweaver initOptions:
--force- Overwrite existing config
generate
Generate types once from your schemas.
npx typeweaver generateOptions:
--config <path>- Custom config file path--output <path>- Override output path--dry-run- Preview without writing--verbose- Show detailed output
watch
Watch schemas and auto-generate types on changes.
npx typeweaver watchOptions:
--config <path>- Custom config file path--output <path>- Override output path
verify
Verify types are in sync with schemas (great for CI/CD).
npx typeweaver verifyinfo
Show current configuration.
npx typeweaver infoclean
Remove all generated type files.
npx typeweaver cleanOptions:
--dry-run- Preview files to be deleted
🎯 Use Cases
1. MERN Stack Development
backend/
models/
User.js
Post.js
typeweaver.config.json
frontend/
types/ ← Auto-generated
index.ts2. Monorepo with Multiple Frontends
{
"orm": "prisma",
"schemaPath": "./backend/schema.prisma",
"outputPath": [
"../web-app/src/types",
"../mobile-app/src/types",
"../admin-dashboard/src/types"
]
}3. API Development
Generate types for your TypeScript SDK:
api/
schema.prisma
typeweaver.config.json → outputs to sdk/types/
sdk/
types/
index.ts ← Auto-generated🔧 Advanced Usage
Custom Type Mapping
{
"customTypeMap": {
"ObjectId": "string",
"Mixed": "Record<string, any>"
}
}Multiple Output Paths
{
"outputPath": ["./frontend/types", "./mobile/types"]
}Exclude Patterns
{
"exclude": ["**/node_modules/**", "**/*.test.js", "**/deprecated/**"]
}🆚 Comparison
| Solution | Zero Migration | Real-Time | No Stack Lock-in | Setup Time | | ------------------- | --------------------- | --------------------- | ---------------- | ---------- | | typeweaver | ✅ | ✅ (<500ms) | ✅ | <1 min | | GraphQL Codegen | ❌ (Requires GraphQL) | ⚠️ (Slow) | ❌ | Weeks | | tRPC | ❌ (Full rewrite) | ✅ | ❌ | Days | | Manual npm packages | ✅ | ❌ (10+ min) | ✅ | Hours | | Monorepo sharing | ⚠️ (Complex) | ⚠️ (Requires rebuild) | ✅ | Days |
🤝 Contributing
Contributions are welcome! See CONTRIBUTING.md.
Development Setup
# Clone repo
git clone https://github.com/yourusername/type-bridge.git
cd type-bridge
# Install dependencies
npm install
# Run tests
npm test
# Test CLI locally
node bin/typeweaver.js generate --help📝 License
MIT © TypeWeaver Contributors
🙏 Acknowledgments
- Inspired by the pain of manual type synchronization
- Built for the full-stack TypeScript community
- Thanks to all contributors and early adopters
📞 Support
- 🐛 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions
- 📧 Email: [email protected]
🗺️ Roadmap
✅ v1.0.0 (Current - November 2025)
- ✅ Prisma support
- ✅ Mongoose support
- ✅ Circular reference detection
- ✅ Nested object support
- ✅ Verification command
- ✅ Better type mappings
- ✅ Production ready!
v1.1.0 (Planned)
- [ ] Custom type mappings configuration
- [ ] Field transformations (removeFields, renameFields)
- [ ] Better error messages with line numbers
v1.2.0 (Planned)
- [ ] DTO generation (CreateDto, UpdateDto, ResponseDto)
- [ ] TypeORM support
- [ ] Sequelize support
v1.3.0+ (Future)
- [ ] Zod schema generation
- [ ] GraphQL schema generation
- [ ] React Query hooks generation
- [ ] tRPC router generation
- [ ] VS Code extension
Made with ❤️ for full-stack TypeScript developers
Stop wasting time on type synchronization. Start using typeweaver today! 🚀
