pyodide / webtypy

Python type definitions for web APIs
Mozilla Public License 2.0
13 stars 3 forks source link

WebIDL only describes web spec, what to do about JS builtins? #13

Open hoodmane opened 9 months ago

hoodmane commented 9 months ago

In #12 I added some type tests. The biggest issue that they seem to reveal is that we don't see JS builtins. For example, suppose someone uses Object:

from js import Object

Object.fromEntries([("a", 1), ("b", 2)])

This sort of code is pretty common in practice and ideally we'd want to be able to typecheck this. Since it's not in the webidl we'd need to get the info from some other source. Unfortunately that seems like a lot of work...

Some thoughts:

  1. Maybe there are typescript type definitions that we can use?
  2. But then maybe those also cover everything in the webidl?
  3. So maybe what is actually needed is a tool for converting from typescript to mypy?
hoodmane commented 9 months ago

Okay I made the following to convert from the typescript declarations for the JS builtins to mypy: https://github.com/hoodmane/ts-to-python

But then maybe those also cover everything in the webidl?

The biggest annoyance I've found compared to webidl is that webidl distinguishes between integer and floating point types but typescript doesn't.