Proposal: Port to TypeScript
See original GitHub issueHello @paldepind, as I know you’re aware, we are making use of this fantastic library in Cycle.js and Motorcycle.js has been using it since about November or December. We’ve been more and more embracing TypeScript and find that the only thing that is difficult is libraries which we are dependent on, not having or having out-of-date typings, which is why I had sent a PR for type definitions previously. However maintaining type-definitions is tedious, painfully error-prone, and now I have many spread across multiple projects that I try my best to keep up-to-date, but has been difficult.
I’ve been working on reviving some neglected parts of Motorcycle, porting to TypeScript, and I’ve been doing my best to ensure that all packages are tree-shaking compatible providing ES2015 builds alongside the commonjs builds. This is where I’ve ran into issues.
Compiling a TypeScript library/application to ES2015 does not allow for commonjs module.exports
(Technically exports.prop
will not work either, but there are workarounds). For type definitions to be correct, they use the following syntax
declare namespace "snabbdom/h" {
export = // ...
}
Which restricts TypeScript to using import h = require('snabbdom/h')
but this disallows compiling to ES2015, and thus disallows tree-shaking compatibility.
So I propose moving the current codebase, starting with a 1:1 port, to TypeScript. Type Definitions will be consistent 100% of the time for users, and are properly versioned with snabbdom itself. Other benefits include ES2015 builds for tree shaking and standards compliance. Another benefit, if tests are written in TypeScript, typings can also be tested.
I would more than happily do this work myself and submit it as a PR, if this is desired.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:16
- Comments:8 (8 by maintainers)
Top GitHub Comments
Sooo, I went ahead and did this work as I mentioned I would, but for the moment its in a separate repo. All of the same tests are passing, and performance within the vdom-benchmark (100 iterations) are not too far from the current codebase (I know these tests arent very definitive), which is better than I expected to be honest. I had much less faith in the compiled output. I tested the commonjs builds of course, there could be a difference in the ES2015 output since there is less difference between TS and ES6.
https://github.com/TylorS/snabbdom-ts https://travis-ci.org/TylorS/snabbdom-ts
For those curious I cloned the vdom-benchmark-snabbdom from https://github.com/vdom-benchmark and simply changed the dependencies.
I did as much as I could to be backwards compatible with the current version but a few things are technically breaking changes. TypeScript does not like the current
thunk()
implementation as it allows for staying backwards compatible with0.4.x
so the signature enforces the use of akey
. The only other thing that is different is when usingrequire()
I’m not too interested in maintaining a virtual-dom library as you’ve already created one that suits all of my needs, so I hope I can take this work and merge it back into mainline if all things are acceptable.
I like TypeScript so I think a port is a splendid idea! 👍
I think we should just change the API of
thunk
as discussed in #143. Making it compatible with TypeScript is yet another benefit.If you’re interested I can create a branch for the TypeScript port and give you commit access?
Btw, one thing I’d like to get done before porting is merging @katyo’s rewrite of the event listeners module. I just need to properly review the PR.