Gradually migrating to TypeScript
See original GitHub issueIs your feature request related to a problem? Please describe. As I don’t encounter any bugs at the moment, I am slightly worried about future maintenance of Leaflet, as I want to use Leaflet in my applications for at least a couple of years. I’ve noticed that the code in some files are still written in old JS syntax and types need to be maintained separately. A mismatch between the types and the actual code could introduce some issues.
Describe the solution you’d like Gradually migrating to TypeScript would be a solution to start with. Why?
- Able to use modern syntax while still supporting older browsers
- All the benefits of TypeScript
- If everything is converted to TS, the
@types/leaflet
package is no longer needed - Overal better development experience
Describe alternatives you’ve considered A solution with minimal impact on the build process and code. Being able to actually use TypeScript and converting existing JS files to TS would be a good start. I’ve quickly tried something out, seems that the build output is almost the same https://github.com/chrisvanmook/Leaflet/pull/1/files.
I would like to know if you, the maintainers / contributors of leaflet, would be open for a similar change like this? In that case I will work on a pull-request, I might need some help with getting karma and leafdoc to work with TS.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:29 (4 by maintainers)
Top GitHub Comments
It solves genuine problems that people experience, but if it’s a good fit for this project is a different discussion. The fact is that the Leaflet types are downloaded over 225.000 times a week, which is half of the downloads of Leaflet itself. This means that 50% of the Leaflet (NPM) user-base is also using TypeScript in one way or another so they seem to think it’s pretty useful.
Adding type definitions (not TypeScript itself) to the NPM package will make it easier for that 50% to do their job, and it has no impact whatsoever for those who do not use it. In fact even if it was decided to allow TypeScript in the code itself, it would still not impact you, since the compiled code is in fact just plain JavaScript.
This will never happen, and should not be a criteria for getting compile time guarantees about the correctness of code.
I’m very wary of TS. Specially when some of the Leaflet code still works around browser quirks, and I fear that TS will try to enforce a strict definition of properties available in
document
,window
and so on. The little I’ve had to work with TS, it got in my way and felt like a burden.Ideally I’d like work to be done on browser-loadable ESM modules (developing without needing to run a bundling toolchain feels so good), move the examples to
<script type=
module>
and deprecate IE10 functionality (along withL.SVG.VML
). I’m personally against complicating the toolchain.