In the discussion on #328 the consensus seems to be that people like type definitions. This moves toward generating types using jsdoc as suggested by @bollwyvl in that thread.

I don't have much Typescript experience so I would very much appreciate it if people could test them out. The types are available as CircleCI artifacts here:
https://3914-322074228-gh.circle-artifacts.com/0/root/repo/build/pyodide.d.ts

@bollwyvl said that

> types that aren't tested are probably worse than no types at all

If anyone could contribute tests, that would be very helpful (I don't know what they should look like). 

The main limitation I ran into with this approach is that Typescript supports Typescript types in jsdoc annotations but jsdoc does not. This means that if we want to automatically generate docs, we have to stick to the much more limited syntax that jsdoc supports. For example, `isPyProxy` should be typed `obj is PyProxy` but this approach does not allow that as far as I can tell. 
Some basic types. In the discussion on #328 the consensus seems to be that people like type definitions. This moves toward generating types using jsdoc as suggested by @bollwyvl in that thread.

I don't have much Typescript experience so I would very much appreciate it if people could test them out. The types are available as CircleCI artifacts here:
https://3914-322074228-gh.circle-artifacts.com/0/root/repo/build/pyodide.d.ts

@bollwyvl said that

> types that aren't tested are probably worse than no types at all

If anyone could contribute tests, that would be very helpful (I don't know what they should look like). 

The main limitation I ran into with this approach is that Typescript supports Typescript types in jsdoc annotations but jsdoc does not. This means that if we want to automatically generate docs, we have to stick to the much more limited syntax that jsdoc supports. For example, `isPyProxy` should be typed `obj is PyProxy` but this approach does not allow that as far as I can tell. 
#define PY_SSIZE_T_CLEAN
#include "Python.h"

#include "keyboard_interrupt.h"
#include <emscripten.h>

static int callback_clock = 1000;

int
pyodide_callback(void)
{
  callback_clock--;
  if (callback_clock == 0) {
    callback_clock = 1000;
    int interrupt_buffer = EM_ASM_INT({
      let result = Module.interrupt_buffer[0];
      Module.interrupt_buffer[0] = 0;
      return result;
    });
    if (interrupt_buffer == 2) {
      PyErr_SetInterrupt();
    }
  }
  return 0;
}

int
keyboard_interrupt_init()
{
  EM_ASM(
    {
      Module.setInterruptBuffer = function(buffer)
      {
        Module.interrupt_buffer = buffer;
        if (buffer) {
          _PyPyodide_SetPyodideCallback($0);
        } else {
          _PyPyodide_SetPyodideCallback(0);
        }
      };
    },
    pyodide_callback);
  return 0;
}

#define PY_SSIZE_T_CLEAN
#include "Python.h"

#include "keyboard_interrupt.h"
#include <emscripten.h>

static int callback_clock = 1000;

int
pyodide_callback(void)
{
  callback_clock--;
  if (callback_clock == 0) {
    callback_clock = 1000;
    int interrupt_buffer = EM_ASM_INT({
      let result = Module.interrupt_buffer[0];
      Module.interrupt_buffer[0] = 0;
      return result;
    });
    if (interrupt_buffer == 2) {
      PyErr_SetInterrupt();
    }
  }
  return 0;
}

int
keyboard_interrupt_init()
{
  EM_ASM(
    {
      Module.setInterruptBuffer = function(buffer)
      {
        Module.interrupt_buffer = buffer;
        if (buffer) {
          _PyPyodide_SetPyodideCallback($0);
        } else {
          _PyPyodide_SetPyodideCallback(0);
        }
      };
    },
    pyodide_callback);
  return 0;
}
