+
Skip to content

akx/typtyp

Repository files navigation

typtyp

Convert Python types and type annotations to TypeScript type definitions.

Features

  • Convert dataclasses, TypedDict, enums, and Pydantic models to TypeScript
  • Support for Python's standard typing primitives
  • Rich type support (dates, UUIDs, complex collections, etc.)
  • Simple API for declaring types for conversion

Installation

pip install typtyp

Usage

from dataclasses import dataclass
from typing import List, Optional
import typtyp

@dataclass
class User:
    name: str
    email: str
    age: Optional[int] = None

@dataclass
class Team:
    name: str
    members: List[User]

# Create a world to collect types
world = typtyp.World()

# Add types to the world
world.add(User)
world.add(Team)

# Generate TypeScript
typescript_code = world.get_typescript()
print(typescript_code)

Output (approximately – you would want to run typtyp's output through a formatter of your liking):

export interface User {
  name: string;
  email: string;
  age: number | null;
}

export interface Team {
  name: string;
  members: User[];
}

About

Generate TypeScript types from Python code

Resources

License

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Languages

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载