{"id":26557,"library":"typescript2python","title":"TypeScript2Python","description":"TypeScript2Python is a transpiler that converts TypeScript type declarations into Python type annotations compatible with Pyright and TypedDict. The current stable version is 2.2.0. It is actively maintained with regular releases. Key differentiators include support for nested objects, optional properties, docstrings, and strict null checks. It is designed for serializable data (JSON) and does not support generics or function signatures.","status":"active","version":"2.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/TheLartians/TypeScript2Python","tags":["javascript","python","typescript","transpiler","types","type-safety","api","json","compiler"],"install":[{"cmd":"npm install typescript2python","lang":"bash","label":"npm"},{"cmd":"yarn add typescript2python","lang":"bash","label":"yarn"},{"cmd":"pnpm add typescript2python","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for parsing TypeScript source files","package":"typescript","optional":false},{"reason":"Used to manipulate and analyze TypeScript AST","package":"ts-morph","optional":false}],"imports":[{"note":"ESM-only since v2.0; CJS require will fail. Use dynamic import() if needed.","wrong":"const TransformConfig = require('typescript2python').TransformConfig","symbol":"TransformConfig","correct":"import { TransformConfig } from 'typescript2python'"},{"note":"Named export, not default. TypeScript users may also import type TransformResult.","wrong":"import TransformResult from 'typescript2python'","symbol":"TransformResult","correct":"import { TransformResult } from 'typescript2python'"},{"note":"Direct named export. The default export does not exist.","wrong":"import * as t2p from 'typescript2python'; t2p.transform()","symbol":"transform","correct":"import { transform } from 'typescript2python'"},{"note":"Used for error handling. No common mistake.","wrong":null,"symbol":"TransformerError","correct":"import { TransformerError } from 'typescript2python'"}],"quickstart":{"code":"import { transform } from 'typescript2python';\n\nconst tsCode = `\nexport type Person = {\n  name: string;\n  age?: number;\n}`;\n\nconst result = transform(tsCode, { filename: 'types.ts' });\nconsole.log(result.code);\n// Output:\n// from typing_extensions import NotRequired, TypedDict\n// class Person(TypedDict):\n//   name: str\n//   age: NotRequired[float]\n","lang":"typescript","description":"How to use the transform function to convert TypeScript type declarations to Python TypedDict classes."},"warnings":[{"fix":"Use import statements or dynamic import() for CJS codebases.","message":"In v2.0, the package switched from CommonJS to ESM. require() calls will throw an error.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use '--nullable-optionals' (correct spelling) in v2.2.0+.","message":"The CLI option '--nullable-optionals' is deprecated in favor of '--nullable-optionals' (typo fixed in v2.2.0).","severity":"deprecated","affected_versions":">=2.0.0 <2.2.0"},{"fix":"Pre-process your TypeScript types to remove unsupported constructs before passing to the transformer.","message":"The transform function does not handle generics, function signatures, or complex conditional types. Use only for serializable data.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update to v2.1.1+ where empty string keys are no longer transpiled.","message":"Empty string keys in objects are silently transformed into functional typed dict definitions before v2.1.1, which may cause runtime errors in Python.","severity":"gotcha","affected_versions":"<2.1.1"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use dynamic import: const { transform } = await import('typescript2python');","cause":"The package is ESM-only since v2.0, not compatible with CommonJS require.","error":"Error: Cannot find module 'typescript2python' when using require()"},{"fix":"Use import { transform } from 'typescript2python';","cause":"Using default import instead of named import.","error":"TypeError: transform is not a function"},{"fix":"Remove generics or replace with concrete types before transpilation.","cause":"Generics are not supported by the transpiler.","error":"TranspilationError: Unsupported syntax: Generic type 'Foo<T>'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}