Finish ts definitions and add tests