Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hoodmane/ts-to-python
https://github.com/hoodmane/ts-to-python
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hoodmane/ts-to-python
- Owner: hoodmane
- Created: 2023-12-04T17:21:24.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-08T09:07:38.000Z (3 months ago)
- Last Synced: 2024-10-31T20:52:31.628Z (2 months ago)
- Language: TypeScript
- Size: 259 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ts-to-python
This is an experimental alternate approach to
[Webtypy](https://github.com/pyodide/webtypy).## WebIDL vs TypeScript as a source of truth
Webtypy ingests the webidl to produce type stubs for the Pyodide `js` module.
`ts-to-python` produces the type stubs from TypeScript `.d.ts` files. The webidl
and TypeScript type declarations contain different information. The ideal
approach would combine both, but it will take some effort to implement.### What information is in the webidl but not in TypeScript declarations?
The webidls distinguish between floating point and integer types, like Python
but unlike TypeScript. Using `.d.ts` files as our source of truth, we have no
choice but to use `float | int` as the number type everywhere.### What information is in TypeScript declarations but not in the webidl?
TypeScript declarations include types for ECMAScript builtins. They are also
available for Node and for many other packages.## Development
It seems to work with node >= 18.
### Generating the types
First you must install the two subdirectories:
```sh
npm install -C type-generation-input-project
npm install -C type-generation
```then to build the types, run:
```sh
npm run -C type-generation build
```### Running tests
You can run the unit tests for the type generation with:
```sh
npm run -C type-generation test
```To run the Python tests for the generated types requires the following setup
first:```sh
cd mypy-tests
python3.11 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```Then from the `mypy-tests` directory run `pytest` to run the tests.