Fix bugs in spec, add TypeScript definitions.