🌐
GitHub
github.com › TheLartians › TypeScript2Python
GitHub - TheLartians/TypeScript2Python: 🚃 Transpile TypeScript types to Python! A TypeScript to Python type transpiler.
🚃 Transpile TypeScript types to Python! A TypeScript to Python type transpiler. - TheLartians/TypeScript2Python
Starred by 27 users
Forked by 3 users
Languages   TypeScript 91.3% | JavaScript 8.7%
Discussions

Side project for converting Python into TypeScript
I definitely recommend you get rid of all of the any types that it outputs. Even if it is just meant as a placeholder, it’s actually worse than not having anything there, because Typescript won’t try to infer the types. In effect, it becomes just JavaScript with pointless Typescript syntax. More on reddit.com
🌐 r/typescript
43
106
December 26, 2020
Are there any tools to transform a large Typescript project into Python? Maybe a transpiler or something?
There are at least two big issues with this: Semantics: Javascript and Python are similar, being dynamic, garbage collected languages. But there is an incredible amount of subtlety to the way both languages behave. You'd end up needing to write your own runtime library to emulate javascript, which is known for many weird quirks. Maybe you could accomplish in a way where the resulting code is readable, but everything would still rely on your support library which provides non-standard behaviors for everything. Libraries: Both languages are known for their rich ecosystems. What libraries does your project use? Maybe you could compile the libraries as well, but what if they're native bindings? At minimum, you'd almost certainly need to provide some emulation for node/deno/bun/whatever runtime you're using. More on reddit.com
🌐 r/Compilers
6
0
May 29, 2025
Python equivalent of Typescript interface - Stack Overflow
For the code completion and type hinting in IDEs, just add static typing for the Person and Address classes and you are already good to go. Assuming you use the latest python3.6, here's a rough equivalent of the typescript classes from your example: More on stackoverflow.com
🌐 stackoverflow.com
How to handle 'this' in typescript/js ? need to convert Python code to Typescript
I have this simple code written in python to create a small Cards game and I want to make the same using typescript but I'm facing a big problem with 'this' in my main class in Typescript this is the More on stackoverflow.com
🌐 stackoverflow.com
People also ask

Can I also convert Python back to TypeScript?
Yes! CodeConvert AI supports bidirectional conversion. You can convert Python to TypeScript just as easily by using our Python to TypeScript converter.
🌐
codeconvert.ai
codeconvert.ai › typescript-to-python-converter
Free TypeScript to Python Converter — AI Code Translation | ...
What types of TypeScript code can be converted to Python?
This tool can convert a wide range of TypeScript code to Python, from simple functions and algorithms to complete programs with classes, error handling, and complex logic. The AI understands both TypeScript and Python idioms and produces natural-looking code.
🌐
codeconvert.ai
codeconvert.ai › typescript-to-python-converter
Free TypeScript to Python Converter — AI Code Translation | ...
How do I convert TypeScript to Python using CodeConvert AI?
Simply paste your TypeScript code into the input box and click the Convert button. Our AI will analyze your TypeScript code and produce equivalent Python code in seconds, preserving the original logic and structure.
🌐
codeconvert.ai
codeconvert.ai › typescript-to-python-converter
Free TypeScript to Python Converter — AI Code Translation | ...
🌐
GitHub
github.com › PerryBhandal › dts_py_transform
GitHub - PerryBhandal/dts_py_transform: Convert Typescript definition files into Python 3 (compliant with PEP-484)
April 15, 2019 - Create a repo which automatically converts all Definitely Typed type annotations into their Python 3 equivalents, along with an easy tool for installing said definitions. Create an easy way to have interop between Python and Javascript, along ...
Forked by 2 users
🌐
GitHub
github.com › carlosmiei › ast-transpiler
GitHub - carlosmiei/ast-transpiler: AST Transpiler that converts Typescript into different languages (PHP, Python, C# (wip))
November 7, 2023 - AST Transpiler that converts Typescript into different languages (PHP, Python, C# (wip)) - carlosmiei/ast-transpiler
Starred by 21 users
Forked by 18 users
Languages   TypeScript 93.7% | C# 5.9% | TypeScript 93.7% | C# 5.9%
🌐
Reddit
reddit.com › r/typescript › side project for converting python into typescript
r/typescript on Reddit: Side project for converting Python into TypeScript
December 26, 2020 - https://github.com/YushchenkoAndrew/ts-doodle/blob/master/doc/Exanple2.png ... I’d be interested in the reverse. TypeScript -> Python ... I once had to deal with a codebase that was a Java->PHP auto conversion. It's suuuper dicy to do this. One of the benefits of using a strongly typed language like Java or Typescript is that you can avoid explicit type checking, since the language does that for you. When you convert to a weakly typed language, what you end up with is a program that is just waiting to fall over or, worse, doesn't fall over when it should.
🌐
GitHub
github.com › Madoshakalaka › python-typing-to-typescript
GitHub - Madoshakalaka/python-typing-to-typescript: convert python typing to interface · GitHub
The program parses Python script with Python's built-in ast, and uses typescript's compiler APIs to transform the ast nodes.
Author   Madoshakalaka
🌐
CodeConvert AI
codeconvert.ai › typescript-to-python-converter
Free TypeScript to Python Converter — AI Code Translation | CodeConvert AI
Instantly convert TypeScript to Python code with AI. Free, fast, and accurate code translation — 60+ languages supported, no signup required.
Find elsewhere
🌐
PyPI
pypi.org › project › ts2python
ts2python
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
GitHub
github.com › cs-cordero › py-ts-interfaces
GitHub - cs-cordero/py-ts-interfaces: A Python to Typescript Interface Generator · GitHub
July 1, 2024 - Teams who wish to use this project are free to do so and also free to fork if you'd like. python --version # requires 3.7+ pip install py-ts-interfaces · In web applications where Python is used in the backend and TypeScript is used in the frontend, it is often the case that the client will make calls to the backend to request some data with some specific pre-defined "shape".
Starred by 111 users
Forked by 12 users
Languages   Python 99.1% | Shell 0.9%
🌐
Reddit
reddit.com › r/compilers › are there any tools to transform a large typescript project into python? maybe a transpiler or something?
r/Compilers on Reddit: Are there any tools to transform a large Typescript project into Python? Maybe a transpiler or something?
May 29, 2025 - "For the first time, TypeScript overtook both Python and JavaScript in August 2025 to become the most used language on GitHub" - GitHub ... I built a tiny tool to convert Pydantic models to TypeScript.
🌐
CodeConvert AI
codeconvert.ai › python-to-typescript-converter
Free Python to TypeScript Converter — AI Code Translation | CodeConvert AI
Simply paste your Python code into the input box and click the Convert button. Our AI will analyze your Python code and produce equivalent TypeScript code in seconds, preserving the original logic and structure.
🌐
Docuwriter
docuwriter.ai › typescript-to-python-code-converter
typescript to python - Code Converter
During conversion, you'll need to account for differences in build tooling, error detection timing, and how the runtime executes your code. TypeScript follows c-style syntax, while Python uses indentation-based syntax. The converter handles mechanical syntax mapping — braces, indentation, and statement delimiters — but you should review control-flow patterns that differ idiomatically between the two.
🌐
Syntha
syntha.ai › converters › typescript-to-python
Free TypeScript to Python Code Converter | Online Programming Language Transformer
Copy the converted Python code and use it in your project. We prioritize your code's security and privacy. Your code is not stored on our servers and is only temporarily processed for conversion. We use OpenAI's secure servers for the conversion process, ensuring your code remains confidential. TypeScript is a superset of JavaScript which primarily provides optional static typing, classes and interfaces.
🌐
transpiler
jarble.github.io › transpiler
transpiler | A universal translator for programming languages
A major goal of this project is to translate TypeScript and JavaScript to other languages that compile to C or native code.
🌐
Codeporting
products.codeporting.ai › convert › typescript-to-python
AI-Powered TypeScript to Python Snippet Converter
Conversion TypeScript to Python using AI involves utilizing natural language processing (NLP) techniques and machine learning algorithms to analyze and understand the TypeScript code, source-to-source code translation may save your time
🌐
PyPI
pypi.org › project › ts2py
ts2py · PyPI
January 17, 2023 - Transpiles TypeScript-Interface-definitions to Python TypedDicts · This repo is born as a fork of ts2python written by Eckhart Arnold arnold@badw.de, Bavarian Academy of Sciences and Humanities. The reason behind this fork was that I needed a simpler way to quickly convert TypeScript interfaces to Python TypedDict.
      » pip install ts2py
    
Published   Jan 17, 2023
Version   0.0.2
Top answer
1 of 9
61

For the code completion and type hinting in IDEs, just add static typing for the Person and Address classes and you are already good to go. Assuming you use the latest python3.6, here's a rough equivalent of the typescript classes from your example:

# spam.py
from typing import Optional, Sequence


class Address:
    street: str
    housenumber: int
    housenumber_postfix: Optional[str]

    def __init__(self, street: str, housenumber: int, 
                 housenumber_postfix: Optional[str] = None) -> None:
        self.street = street
        self.housenumber = housenumber
        self.housenumber_postfix = housenumber_postfix


class Person:
    name: str
    adresses: Sequence[Address]

    def __init__(self, name: str, adresses: Sequence[str]) -> None:
        self.name = name
        self.adresses = adresses


person = Person('Joe', [
    Address('Sesame', 1), 
    Address('Baker', 221, housenumber_postfix='b')
])  # type: Person

I suppose the boilerplate you mentioned emerges when adding the class constructors. This is indeed inavoidable. I would wish default constructors were generated at runtime when not declared explicitly, like this:

class Address:
    street: str
    housenumber: int
    housenumber_postfix: Optional[str]


class Person:
    name: str
    adresses: Sequence[Address]


if __name__ == '__main__':
    alice = Person('Alice', [Address('spam', 1, housenumber_postfix='eggs')])
    bob = Person('Bob', ())  # a tuple is also a sequence

but unfortunately you have to declare them manually.


Edit

As Michael0x2a pointed out in the comment, the need for default constructors is made avoidable in python3.7 which introduced a @dataclass decorator, so one can indeed declare:

@dataclass
class Address:
    street: str
    housenumber: int
    housenumber_postfix: Optional[str]


@dataclass
class Person:
    name: str
    adresses: Sequence[Address]

and get the default impl of several methods, reducing the amount of boilerplate code. Check out PEP 557 for more details.


I guess you could see stub files that can be generated from your code, as some kind of interface files:

$ stubgen spam  # stubgen tool is part of mypy package
Created out/spam.pyi

The generated stub file contains the typed signatures of all non-private classes and functions of the module without implementation:

# Stubs for spam (Python 3.6)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.

from typing import Optional, Sequence

class Address:
    street: str
    housenumber: int
    housenumber_postfix: Optional[str]
    def __init__(self, street: str, housenumber: int, housenumber_postfix: Optional[str]=...) -> None: ...

class Person:
    name: str
    adresses: Sequence[Address]
    def __init__(self, name: str, adresses: Sequence[str]) -> None: ...

person: Person

These stub files are also recognized by IDEs and if your original module is not statically typed, they will use the stub file for type hints and code completion.

2 of 9
24

A TypeScript interface describes a JavaScript object. Such an object is analogous to a Python dictionary with well-known string keys, which is described by a TypedDict.

TypeScript interface example

For example the TypeScript interface:

interface Address {
    street: string;
    housenumber: number;
}

will describe JavaScript objects like:

var someAddress = {
    street: 'SW Gemini Dr.',
    housenumber: 9450,
};

Python TypedDict example

The equivalent Python TypedDict:

from typing import TypedDict

class Address(TypedDict):
    street: str
    housenumber: int

will describe Python dictionaries like:

some_address = {
    'street': 'SW Gemini Dr.',
    'housenumber': 9450,
}

# or equivalently:

some_address = dict(
    street='SW Gemini Dr.',
    housenumber=9450,
)

These dictionaries can be serialized to/from JSON trivially and will conform to the analogous TypeScript interface type.

Note: If you are using Python 2 or older versions of Python 3, you may need to use the older function-based syntax for TypedDict:

from mypy_extensions import TypedDict

Address = TypedDict('Address', {
    'street': str,
    'housenumber': int,
})

Alternatives

There are other ways in Python to represent structures with named properties.

Data classes, available in Python 3.7, have read-write keys. However they cannot be serialized to/from JSON automatically.

from dataclasses import dataclass

@dataclass
class Address:
    street: str
    housenumber: int

my_address = Address(
    street='SW Gemini Dr.',
    housenumber=9450,
)

Named tuples are cheap and have read-only keys. They also cannot be serialized to/from JSON automatically.

from typing import NamedTuple

class Address(NamedTuple):
    street: str
    housenumber: int

my_address = Address(
    street='SW Gemini Dr.',
    housenumber=9450,
)

Simple namespaces, available in Python 3.3, are similar to data classes but are not very well known.

from types import SimpleNamespace

class Address(SimpleNamespace):
    street: str
    housenumber: int

my_address = Address(
    street='SW Gemini Dr.',
    housenumber=9450,
)

attrs is a long-standing third-party library that is similar to data classes but with many more features. attrs is recognized by the mypy typechecker.

import attrs

@attr.s(auto_attribs=True)
class Address:
    street: str
    housenumber: int

my_address = Address(
    street='SW Gemini Dr.',
    housenumber=9450,
)
🌐
AWS
aws.amazon.com › blogs › opensource › generate-python-java-dotnet-software-libraries-from-typescript-source
Generate Python, Java, and .NET software libraries from a TypeScript source | AWS Open Source Blog
March 22, 2021 - The above example library is built and published for JavaScript/TypeScript (at npm), for Python (at PyPI), for Java (at Maven Central) and for .NET/C# (at NuGet). These were compared against equivalent native implementations in the three generated languages to generate performance benchmarks. First let’s take a quick look at the native implementations: The Python implementation is shown below, can be seen in the jsii-native-python GitHub repo, and is published to PyPI:
Top answer
1 of 1
2

The error simply states that single_card is undefined, which it is:

class deck {

  single_card: {
    cType: string;
    cNumber: any;
  };

  // …
}

This will declare the property single_card on the TypeScript class, so that the compiler will accept when you refer to the single_card property of an object of that type (e.g. when doing this.single_card). However, doing so will not actually assign an object of that type to the object. So for the compiled JavaScript (where type information is removed), that property does not exist since you never assign to it. You can easily verify that by looking at the compiled JavaScript there.

So what you would need to do first is assign something to single_card just like you did in the Python version:

this.single_card = {}

However, if you actually look at your Python version, single_card is not a member of the object and it actually doesn’t make any sense for it to be. You are using that to construct the card object you are then adding to the fullDeck array. In Python, it is a local variable, so you should make it a local variable in the TypeScript version too:

buildDeck() {
  for (const t of this.card_type) {
    for (const n of this.card_rank) {
      const single_card = {
          cType: this.card_type[t],
          cNumber: this.card_rank[n]
      };
      this.fullDeck.push(single_card);
    }
  }
}

Btw. you also want to use a for…of loop there instead of for…in.

You should also think about making fullDeck properly typed. Right now it is an array of any, so it can store any object. But what you want to do is actually just keep objects in there that look the way single_card looks. So consider declaring a type for this:

interface SingleCard {
    cType: string;
    cNumber: any;
}

Then, you can properly type fullDeck:

fullDeck: SingleCard[] = [];
🌐
GitHub
github.com › w0rp › python-to-typescript
GitHub - w0rp/python-to-typescript: Python tools for generating TypeScript interfaces from Python types · GitHub
September 9, 2023 - Python tools for generating TypeScript interfaces from Python types - w0rp/python-to-typescript
Starred by 11 users
Forked by 5 users
Languages   Python 96.8% | Shell 3.2%