Analysis updated 2026-05-18
Generate accurate .d.ts files for an Elm app's JavaScript interface automatically.
Catch mistakes like wrong flags or unsubscribed ports at compile time in a TypeScript project embedding Elm.
Wire elm-ts-types into an elm-watch build so type definitions regenerate on every build.
| lydell/elm-ts-types | adnpolymerase/ha-appliance-card | akaakshat246/ecoscore-browser-extension | |
|---|---|---|---|
| Stars | 16 | 16 | 16 |
| Language | JavaScript | JavaScript | JavaScript |
| Setup difficulty | easy | easy | hard |
| Complexity | 2/5 | 2/5 | 3/5 |
| Audience | developer | general | developer |
Figures from each repo's GitHub metadata at analysis time.
elm-ts-types is a small JavaScript library that solves a specific gap in the Elm programming language's tooling. Elm compiles to JavaScript, but once your Elm program becomes plain JavaScript, TypeScript has no way of knowing what functions it exposes, what flags it expects, or what data flows through its ports. This library fixes that by generating TypeScript type definitions directly from your compiled Elm code. You install it as an npm package and call its one function, generateTypeScript, passing it the compiled JavaScript string that the Elm compiler produced. It hands back a string of TypeScript definitions describing the app's init function, the flags it requires, and every port, including which ports send data and which ones subscribe to it, along with the exact shape of the data moving through each one. If you use the elm-watch build tool, this can run automatically as part of its build process so your type definitions stay up to date without extra effort. Once you save that output into a d.ts file, TypeScript recognizes the global Elm object in your project and understands exactly how to call into your Elm app safely, including catching mistakes like passing the wrong flags or forgetting to subscribe to a port. One detail worth knowing: subscribing to a port is typed to expect an async function rather than a plain one. This is intentional. Async functions in JavaScript never throw errors directly, they always return a promise and turn thrown errors into a rejected promise instead, which keeps an error in one port callback from silently breaking unrelated Elm commands running at the same time. Under the hood, the library works by injecting extra code into your compiled Elm output so that instead of actually starting the app, it returns information about its own structure, then evaluates that modified code to recover the true shape of your ports and flags. This keeps it automatically in sync with whatever the Elm compiler actually produces, rather than trying to parse Elm source code by hand.
A small library that generates TypeScript type definitions from compiled Elm JavaScript, covering flags, ports, and init functions.
Mainly JavaScript. The stack also includes JavaScript, TypeScript, Elm.
Setup difficulty is rated easy, with roughly 30min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Verify against the repo before relying on details.