Registry / serialization / typescript2python

typescript2python

JSON →
library2.2.0jsnpmunverified

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.

npm install typescript2python
INSTALL
IMPORT
SIG · TYPESCRIPT2PYTHON
T
typescript2python
serializationjavascriptv2.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TransformConfig
import { TransformConfig } from 'typescript2python'
const TransformConfig = require('typescript2python').TransformConfig
ESM-only since v2.0; CJS require will fail. Use dynamic import() if needed.
TransformResult
import { TransformResult } from 'typescript2python'
import TransformResult from 'typescript2python'
Named export, not default. TypeScript users may also import type TransformResult.
transform
import { transform } from 'typescript2python'
import * as t2p from 'typescript2python'; t2p.transform()
Direct named export. The default export does not exist.
TransformerError
import { TransformerError } from 'typescript2python'
Used for error handling. No common mistake.

How to use the transform function to convert TypeScript type declarations to Python TypedDict classes.

import { transform } from 'typescript2python'; const tsCode = ` export type Person = { name: string; age?: number; }`; const result = transform(tsCode, { filename: 'types.ts' }); console.log(result.code); // Output: // from typing_extensions import NotRequired, TypedDict // class Person(TypedDict): // name: str // age: NotRequired[float]
typescript2python --version
Debug
Known issues
breakingIn v2.0, the package switched from CommonJS to ESM. require() calls will throw an error.
fix
Use import statements or dynamic import() for CJS codebases.
affects: >=2.0.0
deprecatedThe CLI option '--nullable-optionals' is deprecated in favor of '--nullable-optionals' (typo fixed in v2.2.0).
fix
Use '--nullable-optionals' (correct spelling) in v2.2.0+.
affects: >=2.0.0 <2.2.0
gotchaThe transform function does not handle generics, function signatures, or complex conditional types. Use only for serializable data.
fix
Pre-process your TypeScript types to remove unsupported constructs before passing to the transformer.
affects: >=1.0.0
gotchaEmpty string keys in objects are silently transformed into functional typed dict definitions before v2.1.1, which may cause runtime errors in Python.
fix
Update to v2.1.1+ where empty string keys are no longer transpiled.
affects: <2.1.1
Errors
Common errors & fixes
Error: Cannot find module 'typescript2python' when using require()
The package is ESM-only since v2.0, not compatible with CommonJS require.
fix
Use dynamic import: const { transform } = await import('typescript2python');
TypeError: transform is not a function
Using default import instead of named import.
fix
Use import { transform } from 'typescript2python';
TranspilationError: Unsupported syntax: Generic type 'Foo<T>'
Generics are not supported by the transpiler.
fix
Remove generics or replace with concrete types before transpilation.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
typescriptrequiredRequired for parsing TypeScript source files
ts-morphrequiredUsed to manipulate and analyze TypeScript AST
Agent activity
33 hits · last 30 days
node
30
OpenAI (training)
1
Resources