Skip to content

[Feature]: TS Type generation#199

Open
kfirstri wants to merge 15 commits intomainfrom
basic-types-support
Open

[Feature]: TS Type generation#199
kfirstri wants to merge 15 commits intomainfrom
basic-types-support

Conversation

@kfirstri
Copy link
Contributor

@kfirstri kfirstri commented Feb 5, 2026

Note

Description

This PR adds a new base44 types generate command that generates TypeScript declaration files for Base44 projects. The command reads entities, functions, and agents from the project configuration and creates a type-safe base44/.types/types.d.ts file with interfaces for entity schemas and registries for all resources, enabling autocomplete and type safety when using the @base44/sdk in TypeScript projects.

Related Issue

Depends on base44/javascript-sdk#117

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Other (please describe):

Changes Made

  • Added new base44 types parent command with generate subcommand (hidden from help menu)
  • Created src/core/types/ module with:
    • generator.ts: Entity-to-TypeScript interface conversion using json-schema-to-typescript
    • update-project.ts: Automatic tsconfig.json updates to include generated types
  • Added dependencies for type generation:
    • json-schema-to-typescript: Converts JSON Schema to TypeScript interfaces
    • common-tags: Template string formatting for clean code generation
    • Related type definitions (@types/json-schema, @types/common-tags)
  • Implemented entity interface generation from JSON schemas with support for nested objects, arrays, enums, and Base44 property types
  • Implemented registry generation for EntityTypeRegistry, FunctionNameRegistry, and AgentNameRegistry
  • Added automatic tsconfig.json updates to include base44/.types/*.d.ts in the include array
  • Added comprehensive test coverage in tests/cli/types_generate.spec.ts with fixtures
  • Added constants TYPES_OUTPUT_SUBDIR and TYPES_FILENAME to src/core/consts.ts
  • Added getTypesOutputPath() helper to src/core/config.ts
  • Added TypeGenerationError to error hierarchy in src/core/errors.ts
  • Registered types command in CLI program at src/cli/program.ts
  • Increased version check timeout from 500ms to 1000ms to improve reliability
  • Updated template .gitignore files to exclude generated .types/ directory
  • Removed deprecated property types (binary, file, regex) from entity schema

Testing

  • I have tested these changes locally
  • I have added/updated tests as needed
  • All tests pass (bun test)

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • My changes generate no new warnings
  • I have updated CLAUDE.md with architectural changes

Additional Notes

The generated types file augments the @base44/sdk module with TypeScript interfaces for entity schemas and registries for functions and agents. Entity names are converted to PascalCase for interface names (e.g., user_profileUserProfile). The generator handles empty projects gracefully by generating a placeholder file with helpful comments.

Command usage:

base44 types generate  # Generates base44/.types/types.d.ts

The command automatically updates tsconfig.json to include the generated types if the file exists. The types command is currently hidden from the help menu while the feature is being finalized.

Module Structure (to be documented in CLAUDE.md):

src/core/types/
├── generator.ts       # Entity-to-TypeScript conversion & registry generation
├── update-project.ts  # Automatic tsconfig.json updates
└── index.ts           # Barrel exports

🤖 Generated by Claude | 2026-02-05 15:45 UTC

@github-actions
Copy link
Contributor

github-actions bot commented Feb 5, 2026

🚀 Package Preview Available!


Install this PR's preview build with npm:

npm i @base44-preview/cli@0.0.28-pr.199.7452a77

Prefer not to change any import paths? Install using npm alias so your code still imports base44:

npm i "base44@npm:@base44-preview/cli@0.0.28-pr.199.7452a77"

Or add it to your package.json dependencies:

{
  "dependencies": {
    "base44": "npm:@base44-preview/cli@0.0.28-pr.199.7452a77"
  }
}

Preview published to npm registry — try new features instantly!

@claude
Copy link

claude bot commented Feb 5, 2026

Posting inline comments on PR #199...

@claude
Copy link

claude bot commented Feb 5, 2026

Code review

Found 1 issue that needs attention:

Issue: Incorrect command in generated file comments

Files affected:

  • src/core/types/template.ts (lines 20 and 28)

Problem:
The auto-generated comments in both HEADER and EMPTY_TEMPLATE constants say:

// Regenerate with: base44 types

However, the correct command is:

// Regenerate with: base44 types generate

Why this matters:
The types command is a parent command with a generate subcommand (see program.ts:241-243). Running just base44 types will show help text, not regenerate the types file. Users following the comment instruction would get confused.

Suggested fix:
Update both occurrences to include the full command: base44 types generate


Review scope: Checked for bugs and CLAUDE.md compliance.

@kfirstri
Copy link
Contributor Author

kfirstri commented Feb 5, 2026

Gap i see - the "Task" returned from the sdk doesn't not have the predefined fields like "is_sample", "id", "created_by"....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant