question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Convert htmx to TypeScript 😍

See original GitHub issue

TypeScript would bring lots of DX benefits to the htmx source code. Besides the obvious strict type checking, we would be able to write code using the latest and greatest ECMAScript 2021, but continue compiling to ES5 (to support IE11), or any version of ECMAScript really, with a single config setting.

{
  "compilerOptions": {
    "target": "ES5"
  }
}

I’ve started a WIP branch in which I’ve converted htmx.js to htmx.ts, changing the minimum amount of code possible, and it is compiling with all tests passing.

@1cg in theory, we could merge this branch into the dev branch before the next minor release, and start converting the source code incrementally.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:12
  • Comments:32 (7 by maintainers)

github_iconTop GitHub Comments

8reactions
benpatecommented, Oct 14, 2021

I think this may have already been settled, but I’ll just add this for posterity. Typescript is made for codebases EXACTLY like htmx. The compiler can be set to work with existing *.js files, and there’s even an option to include (almost) all of the Typescript annotations as backwards-compatible JSDoc comments.

A small band of Typescript fanatics (including me) have been sneaking JSDoc/Typescript comments into htmx and hyperscript for a while, now 😃 This gives us the benefits of using Typescript with little additional developer overhead. The comments are a little more clunky than pure Typescript, but it lets us get started while we work out the infrastructure.

5reactions
gnatcommented, Sep 29, 2021

Of course up to @1cg to decide if this switch is actually worthwhile, but will have to say no thanks because:

  • Increased barrier for contributions.
  • More complex, slower build process.
  • Type checking may not even be of tangible benefit for htmx (htmx has a nice test suite).

The ECMAScript spec will probably supersede TypeScript in the near future anyway. This has happened historically with other dead Javascript dialects (example: when classes were included in ES6).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Refactoring a Static HTML Site Into Typescript, Part 1 of 2
There are two big pieces of work: Converting the content from static HTML to Typescript functions. Converting the navigation from href link to ......
Read more >
HTML to JSX - Transform Tools
An online playground to convert HTML to JSX.
Read more >
Convert HTML Javascript to Angular TypeScript?!? : r/Angular2
Please make sure your browser load file app.js. You can add script direct to index.html file. if you don't want to bundle that...
Read more >
How To Convert Html Website To React Js App (Simple Method)
How to convert an HTML website into a react js application and how to host it ... Get 82% discount 😍 from hostinger...
Read more >
Parcel
Start with an HTML file. Add a <script> tag. Maybe some CSS. How about TypeScript? SASS? Images? No problem. Parcel works out of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found